54 #include "llvm/ADT/STLForwardCompat.h"
55 #include "llvm/ADT/SmallString.h"
56 #include "llvm/ADT/StringExtras.h"
57 #include "llvm/TargetParser/Triple.h"
62 #include <unordered_map>
64 using namespace clang;
80 TypeNameValidatorCCC(
bool AllowInvalid,
bool WantClass =
false,
81 bool AllowTemplates =
false,
82 bool AllowNonTemplates =
true)
83 : AllowInvalidDecl(AllowInvalid), WantClassName(WantClass),
84 AllowTemplates(AllowTemplates), AllowNonTemplates(AllowNonTemplates) {
85 WantExpressionKeywords =
false;
86 WantCXXNamedCasts =
false;
87 WantRemainingKeywords =
false;
92 if (!AllowInvalidDecl && ND->isInvalidDecl())
96 return AllowTemplates;
98 bool IsType = isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
102 if (AllowNonTemplates)
107 if (AllowTemplates) {
108 auto *RD = dyn_cast<CXXRecordDecl>(ND);
109 if (!RD || !RD->isInjectedClassName())
111 RD = cast<CXXRecordDecl>(RD->getDeclContext());
112 return RD->getDescribedClassTemplate() ||
113 isa<ClassTemplateSpecializationDecl>(RD);
119 return !WantClassName && candidate.
isKeyword();
122 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
123 return std::make_unique<TypeNameValidatorCCC>(*
this);
127 bool AllowInvalidDecl;
130 bool AllowNonTemplates;
136 enum class UnqualifiedTypeNameLookupResult {
147 static UnqualifiedTypeNameLookupResult
152 return UnqualifiedTypeNameLookupResult::NotFound;
154 UnqualifiedTypeNameLookupResult FoundTypeDecl =
155 UnqualifiedTypeNameLookupResult::NotFound;
158 if (
auto *BaseTT =
Base.getType()->getAs<
TagType>())
159 BaseRD = BaseTT->getAsCXXRecordDecl();
163 if (!TST || !TST->isDependentType())
165 auto *TD = TST->getTemplateName().getAsTemplateDecl();
168 if (
auto *BasePrimaryTemplate =
169 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) {
171 BaseRD = BasePrimaryTemplate;
172 else if (
auto *CTD = dyn_cast<ClassTemplateDecl>(TD)) {
174 CTD->findPartialSpecialization(
Base.getType()))
182 if (!isa<TypeDecl>(ND))
183 return UnqualifiedTypeNameLookupResult::FoundNonType;
184 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
186 if (FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound) {
188 case UnqualifiedTypeNameLookupResult::FoundNonType:
189 return UnqualifiedTypeNameLookupResult::FoundNonType;
190 case UnqualifiedTypeNameLookupResult::FoundType:
191 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
193 case UnqualifiedTypeNameLookupResult::NotFound:
200 return FoundTypeDecl;
208 UnqualifiedTypeNameLookupResult FoundTypeDecl =
209 UnqualifiedTypeNameLookupResult::NotFound;
211 DC && FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound;
215 RD = dyn_cast<CXXRecordDecl>(DC);
219 if (FoundTypeDecl != UnqualifiedTypeNameLookupResult::FoundType)
225 S.
Diag(NameLoc, diag::ext_found_in_dependent_base) << &II;
247 bool WantNontrivialTypeSourceInfo =
true) {
249 case Type::DeducedTemplateSpecialization:
251 case Type::InjectedClassName:
254 case Type::UnresolvedUsing:
259 case Type::ObjCInterface:
260 case Type::ObjCTypeParam:
261 case Type::TemplateTypeParm:
264 llvm_unreachable(
"Unexpected Type Class");
272 if (!WantNontrivialTypeSourceInfo)
276 Builder.pushTypeSpec(
T).setNameLoc(NameLoc);
293 bool HasTrailingDot,
ParsedType ObjectTypePtr,
294 bool IsCtorOrDtorName,
295 bool WantNontrivialTypeSourceInfo,
296 bool IsClassTemplateDeductionContext,
300 bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
301 getLangOpts().CPlusPlus17 && !IsCtorOrDtorName &&
302 !isClassName && !HasTrailingDot;
309 LookupCtx = computeDeclContext(ObjectType);
311 LookupCtx = computeDeclContext(*SS,
false);
314 if (isDependentScopeSpecifier(*SS)) {
327 !isClassName && !IsCtorOrDtorName)
329 bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
330 if (IsImplicitTypename) {
333 Diag(QualifiedLoc, diag::warn_cxx17_compat_implicit_typename);
335 Diag(QualifiedLoc, diag::ext_implicit_typename)
342 if (WantNontrivialTypeSourceInfo)
359 RequireCompleteDeclContext(*SS, LookupCtx))
373 LookupQualifiedName(Result, LookupCtx);
375 if (ObjectTypePtr && Result.empty()) {
382 LookupName(Result, S);
386 LookupName(Result, S);
390 if (Result.empty() && getLangOpts().MSVCCompat && (!SS || SS->
isEmpty())) {
399 switch (Result.getResultKind()) {
402 TypeNameValidatorCCC CCC(
true, isClassName,
403 AllowDeducedTemplate);
405 S, SS, CCC, CTK_ErrorRecovery);
408 bool MemberOfUnknownSpecialization;
417 if (Correction && (NNS || NewII != &II) &&
422 isTemplateName(S, *NewSSPtr,
false,
TemplateName,
nullptr,
false,
423 Template, MemberOfUnknownSpecialization))) {
425 isClassName, HasTrailingDot, ObjectTypePtr,
427 WantNontrivialTypeSourceInfo,
428 IsClassTemplateDeductionContext);
430 diagnoseTypo(Correction,
431 PDiag(diag::err_unknown_type_or_class_name_suggest)
432 << Result.getLookupName() << isClassName);
435 *CorrectedII = NewII;
440 Result.suppressDiagnostics();
456 Result.suppressDiagnostics();
466 Result.suppressDiagnostics();
472 Res != ResEnd; ++Res) {
474 if (isa<TypeDecl, ObjCInterfaceDecl, UnresolvedUsingIfExistsDecl>(
481 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Res);
493 Result.suppressDiagnostics();
504 IIDecl = Result.getFoundDecl();
505 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Result.begin());
509 assert(IIDecl &&
"Didn't find decl");
512 if (
TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
516 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
517 auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
518 if (!isClassName && !IsCtorOrDtorName && LookupRD && FoundRD &&
519 FoundRD->isInjectedClassName() &&
521 Diag(NameLoc, diag::err_out_of_line_qualified_id_type_names_constructor)
524 DiagnoseUseOfDecl(IIDecl, NameLoc);
527 MarkAnyDeclReferenced(TD->getLocation(), TD,
false);
529 (void)DiagnoseUseOfDecl(IDecl, NameLoc);
532 FoundUsingShadow =
nullptr;
533 }
else if (
auto *UD = dyn_cast<UnresolvedUsingIfExistsDecl>(IIDecl)) {
534 (void)DiagnoseUseOfDecl(UD, NameLoc);
537 }
else if (AllowDeducedTemplate) {
539 assert(!FoundUsingShadow || FoundUsingShadow->
getTargetDecl() == TD);
545 FoundUsingShadow =
nullptr;
551 Result.suppressDiagnostics();
555 if (FoundUsingShadow)
558 return buildNamedType(*
this, SS,
T, NameLoc, WantNontrivialTypeSourceInfo);
566 auto *ND = dyn_cast<NamespaceDecl>(DC);
567 if (ND && !ND->isInline() && !ND->isAnonymousNamespace())
569 else if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
571 RD->getTypeForDecl());
572 else if (isa<TranslationUnitDecl>(DC))
575 llvm_unreachable(
"something isn't in TU scope?");
586 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
587 if (MD->getParent()->hasAnyDependentBases())
595 bool IsTemplateTypeArg) {
596 assert(getLangOpts().MSVCCompat &&
"shouldn't be called in non-MSVC mode");
599 if (IsTemplateTypeArg && getCurScope()->isTemplateParamScope()) {
608 Diag(NameLoc, diag::ext_ms_delayed_template_argument) << &II;
614 RD->getTypeForDecl());
618 Diag(NameLoc, diag::ext_undeclared_unqual_id_with_dependent_base) << &II
639 return CreateParsedType(
T, Builder.getTypeSourceInfo(Context,
T));
650 LookupName(R, S,
false);
654 switch (TD->getTagKind()) {
686 if (CurContext->isRecord()) {
696 return S->isFunctionPrototypeScope();
698 return CurContext->isFunctionOrMethod() || S->isFunctionPrototypeScope();
706 bool IsTemplateName) {
711 SuggestedType =
nullptr;
715 TypeNameValidatorCCC CCC(
false,
false,
720 CCC, CTK_ErrorRecovery)) {
722 bool CanRecover = !IsTemplateName;
723 if (Corrected.isKeyword()) {
725 diagnoseTypo(Corrected,
726 PDiag(IsTemplateName ? diag::err_no_template_suggest
727 : diag::err_unknown_typename_suggest)
729 II = Corrected.getCorrectionAsIdentifierInfo();
732 if (!SS || !SS->
isSet()) {
733 diagnoseTypo(Corrected,
734 PDiag(IsTemplateName ? diag::err_no_template_suggest
735 : diag::err_unknown_typename_suggest)
737 }
else if (
DeclContext *DC = computeDeclContext(*SS,
false)) {
738 std::string CorrectedStr(Corrected.getAsString(getLangOpts()));
739 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
740 II->
getName().equals(CorrectedStr);
741 diagnoseTypo(Corrected,
743 ? diag::err_no_member_template_suggest
744 : diag::err_unknown_nested_typename_suggest)
745 << II << DC << DroppedSpecifier << SS->
getRange(),
748 llvm_unreachable(
"could not have corrected a typo here");
755 if (Corrected.getCorrectionSpecifier())
756 tmpSS.
MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
760 getTypeName(*Corrected.getCorrectionAsIdentifierInfo(), IILoc, S,
761 tmpSS.
isSet() ? &tmpSS : SS,
false,
false,
nullptr,
768 if (getLangOpts().
CPlusPlus && !IsTemplateName) {
771 Name.setIdentifier(II, IILoc);
774 bool MemberOfUnknownSpecialization;
775 if (isTemplateName(S, SS ? *SS : EmptySS,
false,
776 Name,
nullptr,
true, TemplateResult,
778 diagnoseMissingTemplateArguments(TemplateResult.
get(), IILoc);
787 Diag(IILoc, IsTemplateName ? diag::err_no_template
788 : diag::err_unknown_typename)
790 else if (
DeclContext *DC = computeDeclContext(*SS,
false))
791 Diag(IILoc, IsTemplateName ? diag::err_no_member_template
792 : diag::err_typename_nested_not_found)
797 }
else if (isDependentScopeSpecifier(*SS)) {
798 unsigned DiagID = diag::err_typename_missing;
799 if (getLangOpts().MSVCCompat && isMicrosoftMissingTypename(SS, S))
800 DiagID = diag::ext_typename_missing;
807 *SS, *II, IILoc).
get();
810 "Invalid scope specifier has already been diagnosed");
818 NextToken.
is(tok::less);
821 if (isa<TypeDecl>(*I) || isa<ObjCInterfaceDecl>(*I))
824 if (CheckTemplate && isa<TemplateDecl>(*I))
838 StringRef FixItTagName;
839 switch (Tag->getTagKind()) {
841 FixItTagName =
"class ";
845 FixItTagName =
"enum ";
849 FixItTagName =
"struct ";
853 FixItTagName =
"__interface ";
857 FixItTagName =
"union ";
861 StringRef TagName = FixItTagName.drop_back();
862 SemaRef.
Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
863 << Name << TagName << SemaRef.
getLangOpts().CPlusPlus
868 SemaRef.
Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
883 const Token &NextToken,
888 assert(NextToken.
isNot(tok::coloncolon) &&
889 "parse nested name specifiers before calling ClassifyName");
891 isCurrentClassName(*Name, S, &SS)) {
899 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
900 LookupParsedName(Result, S, &SS, !CurMethod);
907 if (Result.empty() && SS.
isEmpty() && getLangOpts().MSVCCompat) {
918 DeclResult Ivar = LookupIvarInObjCMethod(Result, S, Name);
922 return NameClassification::NonType(cast<NamedDecl>(Ivar.
get()));
926 LookupBuiltin(Result);
929 bool SecondTry =
false;
930 bool IsFilteredTemplateName =
false;
933 switch (Result.getResultKind()) {
937 if (SS.
isEmpty() && NextToken.
is(tok::l_paren)) {
941 return NameClassification::UndeclaredNonType();
957 if (getLangOpts().implicitFunctionsAllowed()) {
958 if (
NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *Name, S))
959 return NameClassification::NonType(D);
970 return NameClassification::UndeclaredTemplate(Template);
976 if (!getLangOpts().
CPlusPlus && !SecondTry &&
983 if (!SecondTry && CCC) {
986 CorrectTypo(Result.getLookupNameInfo(), Result.getLookupKind(), S,
987 &SS, *CCC, CTK_ErrorRecovery)) {
988 unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
989 unsigned QualifiedDiag = diag::err_no_member_suggest;
991 NamedDecl *FirstDecl = Corrected.getFoundDecl();
992 NamedDecl *UnderlyingFirstDecl = Corrected.getCorrectionDecl();
993 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
994 UnderlyingFirstDecl && isa<TemplateDecl>(UnderlyingFirstDecl)) {
995 UnqualifiedDiag = diag::err_no_template_suggest;
996 QualifiedDiag = diag::err_no_member_template_suggest;
997 }
else if (UnderlyingFirstDecl &&
998 (isa<TypeDecl>(UnderlyingFirstDecl) ||
999 isa<ObjCInterfaceDecl>(UnderlyingFirstDecl) ||
1000 isa<ObjCCompatibleAliasDecl>(UnderlyingFirstDecl))) {
1001 UnqualifiedDiag = diag::err_unknown_typename_suggest;
1002 QualifiedDiag = diag::err_unknown_nested_typename_suggest;
1006 diagnoseTypo(Corrected, PDiag(UnqualifiedDiag) << Name);
1008 std::string CorrectedStr(Corrected.getAsString(getLangOpts()));
1009 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
1010 Name->getName().equals(CorrectedStr);
1011 diagnoseTypo(Corrected, PDiag(QualifiedDiag)
1012 << Name << computeDeclContext(SS,
false)
1013 << DroppedSpecifier << SS.
getRange());
1017 Name = Corrected.getCorrectionAsIdentifierInfo();
1020 if (Corrected.isKeyword())
1026 Result.setLookupName(Corrected.getCorrection());
1028 Result.addDecl(FirstDecl);
1036 LookupIvarInObjCMethod(Result, S, Ivar->getIdentifier());
1040 return NameClassification::NonType(Ivar);
1048 Result.suppressDiagnostics();
1066 return NameClassification::DependentNonType();
1075 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1076 hasAnyAcceptableTemplateNames(Result,
true,
1089 FilterAcceptableTemplateNames(Result);
1090 if (!Result.isAmbiguous()) {
1091 IsFilteredTemplateName =
true;
1100 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1101 (IsFilteredTemplateName ||
1102 hasAnyAcceptableTemplateNames(
1117 if (!IsFilteredTemplateName)
1118 FilterAcceptableTemplateNames(Result);
1120 bool IsFunctionTemplate;
1123 if (Result.end() - Result.begin() > 1) {
1124 IsFunctionTemplate =
true;
1127 }
else if (!Result.empty()) {
1128 auto *TD = cast<TemplateDecl>(getAsTemplateNameDecl(
1129 *Result.begin(),
true,
1131 IsFunctionTemplate = isa<FunctionTemplateDecl>(TD);
1132 IsVarTemplate = isa<VarTemplateDecl>(TD);
1135 dyn_cast<UsingShadowDecl>(*Result.begin());
1136 assert(!FoundUsingShadow ||
1137 TD == cast<TemplateDecl>(FoundUsingShadow->
getTargetDecl()));
1147 IsFunctionTemplate =
true;
1151 if (IsFunctionTemplate) {
1155 Result.suppressDiagnostics();
1157 return NameClassification::FunctionTemplate(Template);
1160 return IsVarTemplate ? NameClassification::VarTemplate(Template)
1161 : NameClassification::TypeTemplate(Template);
1166 if (
const auto *USD = dyn_cast<UsingShadowDecl>(Found))
1171 NamedDecl *FirstDecl = (*Result.begin())->getUnderlyingDecl();
1173 DiagnoseUseOfDecl(
Type, NameLoc);
1174 MarkAnyDeclReferenced(
Type->getLocation(),
Type,
false);
1175 return BuildTypeFor(
Type, *Result.begin());
1182 dyn_cast<ObjCCompatibleAliasDecl>(FirstDecl))
1183 Class = Alias->getClassInterface();
1187 DiagnoseUseOfDecl(
Class, NameLoc);
1189 if (NextToken.
is(tok::period)) {
1192 Result.suppressDiagnostics();
1200 if (isa<ConceptDecl>(FirstDecl)) {
1202 if (
auto *USD = dyn_cast<UsingShadowDecl>(Result.getRepresentativeDecl()))
1204 return NameClassification::Concept(
1208 if (
auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(FirstDecl)) {
1209 (void)DiagnoseUseOfDecl(EmptyD, NameLoc);
1214 if (isa<TemplateDecl>(FirstDecl) && !isa<FunctionTemplateDecl>(FirstDecl) &&
1215 !isa<VarTemplateDecl>(FirstDecl))
1216 return NameClassification::TypeTemplate(
1221 bool NextIsOp = NextToken.
isOneOf(tok::amp, tok::star);
1222 if ((NextToken.
is(tok::identifier) ||
1227 DiagnoseUseOfDecl(
Type, NameLoc);
1228 return BuildTypeFor(
Type, *Result.begin());
1235 bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.
is(tok::l_paren));
1236 if (Result.isSingleResult() && !ADL &&
1238 return NameClassification::NonType(Result.getRepresentativeDecl());
1241 Result.suppressDiagnostics();
1244 Result.getLookupNameInfo(), ADL, Result.begin(), Result.end(),
1251 assert(getLangOpts().
CPlusPlus &&
"ADL-only call in C?");
1253 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
1254 return BuildDeclarationNameExpr(SS, Result,
true);
1261 bool IsAddressOfOperand) {
1264 NameInfo, IsAddressOfOperand,
1271 const Token &NextToken) {
1272 if (getCurMethodDecl() && SS.
isEmpty())
1274 return BuildIvarRefExpr(S, NameLoc, Ivar);
1278 Result.addDecl(Found);
1279 Result.resolveKind();
1281 bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.
is(tok::l_paren));
1282 return BuildDeclarationNameExpr(SS, Result, ADL,
true);
1288 auto *ULE = cast<UnresolvedLookupExpr>(E);
1289 if ((*ULE->decls_begin())->isCXXClassMember()) {
1291 SS.
Adopt(ULE->getQualifierLoc());
1294 LookupResult Result(*
this, ULE->getName(), ULE->getNameLoc(),
1295 LookupOrdinaryName);
1296 Result.setNamingClass(ULE->getNamingClass());
1297 for (
auto I = ULE->decls_begin(), E = ULE->decls_end(); I != E; ++I)
1298 Result.addDecl(*I, I.getAccess());
1299 Result.resolveKind();
1300 return BuildPossibleImplicitMemberExpr(SS,
SourceLocation(), Result,
1311 auto *TD = Name.getAsTemplateDecl();
1313 return TemplateNameKindForDiagnostics::DependentTemplate;
1314 if (isa<ClassTemplateDecl>(TD))
1315 return TemplateNameKindForDiagnostics::ClassTemplate;
1316 if (isa<FunctionTemplateDecl>(TD))
1317 return TemplateNameKindForDiagnostics::FunctionTemplate;
1318 if (isa<VarTemplateDecl>(TD))
1319 return TemplateNameKindForDiagnostics::VarTemplate;
1320 if (isa<TypeAliasTemplateDecl>(TD))
1321 return TemplateNameKindForDiagnostics::AliasTemplate;
1322 if (isa<TemplateTemplateParmDecl>(TD))
1323 return TemplateNameKindForDiagnostics::TemplateTemplateParam;
1324 if (isa<ConceptDecl>(TD))
1325 return TemplateNameKindForDiagnostics::Concept;
1326 return TemplateNameKindForDiagnostics::DependentTemplate;
1331 "The next DeclContext should be lexically contained in the current one.");
1337 assert(CurContext &&
"DeclContext imbalance!");
1339 CurContext = CurContext->getLexicalParent();
1340 assert(CurContext &&
"Popped translation unit!");
1349 CurContext = cast<TagDecl>(D)->getDefinition();
1350 assert(CurContext &&
"skipping definition of undefined tag");
1353 S->setEntity(CurContext->getLookupParent());
1358 CurContext =
static_cast<decltype(CurContext)
>(Context);
1381 assert(!S->getEntity() &&
"scope already has entity");
1384 Scope *Ancestor = S->getParent();
1386 assert(Ancestor->
getEntity() == CurContext &&
"ancestor context mismatch");
1392 if (S->getParent()->isTemplateParamScope()) {
1395 EnterTemplatedContext(S->getParent(), DC);
1400 assert(S->getEntity() == CurContext &&
"Context imbalance!");
1404 Scope *Ancestor = S->getParent();
1413 assert(S->isTemplateParamScope() &&
1414 "expected to be initializing a template parameter scope");
1437 unsigned ScopeDepth = getTemplateDepth(S);
1438 for (; S && S->isTemplateParamScope(); S = S->getParent(), --ScopeDepth) {
1442 cast<Decl>(DC)->getDescribedTemplateParams()) {
1443 unsigned DCDepth = TPL->getDepth() + 1;
1444 if (DCDepth > ScopeDepth)
1446 if (ScopeDepth == DCDepth)
1451 S->setLookupEntity(SearchDCAfterScope);
1465 "The next DeclContext should be lexically contained in the current one.");
1467 S->setEntity(CurContext);
1469 for (
unsigned P = 0, NumParams = FD->
getNumParams();
P < NumParams; ++
P) {
1474 IdResolver.AddDecl(Param);
1482 assert(CurContext &&
"DeclContext imbalance!");
1483 CurContext = CurContext->getLexicalParent();
1484 assert(CurContext &&
"Popped translation unit!");
1513 return ND->
hasAttr<OverloadableAttr>();
1516 return Previous.getFoundDecl()->hasAttr<OverloadableAttr>();
1526 while (S->getEntity() && S->getEntity()->isTransparentContext())
1533 CurContext->addDecl(D);
1541 if (isa<FunctionDecl>(D) &&
1542 cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())
1551 IEnd = IdResolver.end();
1552 for (; I != IEnd; ++I) {
1555 IdResolver.RemoveDecl(*I);
1564 if (isa<LabelDecl>(D) && !cast<LabelDecl>(D)->isGnuLocal()) {
1568 for (I = IdResolver.begin(D->
getDeclName()); I != IEnd; ++I) {
1570 if (IDC == CurContext) {
1571 if (!S->isDeclScope(*I))
1573 }
else if (IDC->
Encloses(CurContext))
1577 IdResolver.InsertDeclAfter(I, D);
1579 IdResolver.AddDecl(D);
1581 warnOnReservedIdentifier(D);
1585 bool AllowInlineNamespace)
const {
1586 return IdResolver.isDeclInScope(D, Ctx, S, AllowInlineNamespace);
1593 if (ScopeDC->getPrimaryContext() == TargetDC)
1595 }
while ((S = S->getParent()));
1607 bool ConsiderLinkage,
1608 bool AllowInlineNamespace) {
1613 if (isDeclInScope(D, Ctx, S, AllowInlineNamespace))
1638 makeMergedDefinitionVisible(New);
1669 if (NewIsModuleInterface || OldIsModuleInterface) {
1675 << NewIsModuleInterface
1677 << OldIsModuleInterface
1708 if (!IsNewExported && !IsOldExported)
1714 assert(IsNewExported);
1722 Diag(New->
getLocation(), diag::err_redeclaration_non_exported) << New << S;
1730 if (CheckRedeclarationModuleOwnership(New, Old))
1733 if (CheckRedeclarationExported(New, Old))
1757 assert(getASTContext().isSameEntity(New, Old) &&
1758 "New and Old are not the same definition, we should diagnostic it "
1759 "immediately instead of checking it.");
1760 assert(
const_cast<Sema *
>(
this)->isReachable(New) &&
1761 const_cast<Sema *
>(
this)->isReachable(Old) &&
1762 "We shouldn't see unreachable definitions here.");
1810 return OldM == NewM;
1817 return isa<UsingShadowDecl>(D) ||
1818 isa<UnresolvedUsingTypenameDecl>(D) ||
1819 isa<UnresolvedUsingValueDecl>(D);
1847 return CD->isCopyConstructor();
1863 bool Sema::mightHaveNonExternalLinkage(
const DeclaratorDecl *D) {
1866 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(DC)){
1867 if (!RD->hasNameForLinkage())
1896 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1902 FD->getMemberSpecializationInfo() && !FD->isOutOfLine())
1905 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1910 if (FD->isInlined() && !
isMainFileLoc(*
this, FD->getLocation()))
1914 if (FD->doesThisDeclarationHaveABody() &&
1917 }
else if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1927 if (VD->isStaticDataMember() &&
1930 if (VD->isStaticDataMember() &&
1932 VD->getMemberSpecializationInfo() && !VD->isOutOfLine())
1935 if (VD->isInline() && !
isMainFileLoc(*
this, VD->getLocation()))
1944 return mightHaveNonExternalLinkage(D);
1951 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1953 if (FD !=
First && ShouldWarnIfUnusedFileScopedDecl(
First))
1957 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1959 if (VD !=
First && ShouldWarnIfUnusedFileScopedDecl(
First))
1963 if (ShouldWarnIfUnusedFileScopedDecl(D))
1964 UnusedFileScopedDecls.push_back(D);
1972 if (
const auto *DD = dyn_cast<DecompositionDecl>(D)) {
1976 bool IsAllPlaceholders =
true;
1977 for (
const auto *BD : DD->bindings()) {
1978 if (BD->isReferenced())
1980 IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts);
1982 if (IsAllPlaceholders)
1993 if (D->
hasAttr<UnusedAttr>() || D->
hasAttr<ObjCPreciseLifetimeAttr>() ||
1997 if (isa<LabelDecl>(D))
2003 if (
const auto *R = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
2006 WithinFunction || (R->isLocalClass() && !R->isDependentType());
2007 if (!WithinFunction)
2010 if (isa<TypedefNameDecl>(D))
2014 if (!isa<VarDecl>(D) || isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D))
2018 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2020 const Expr *Init = VD->getInit();
2021 if (
const auto *Cleanups = dyn_cast_if_present<ExprWithCleanups>(Init))
2022 Init = Cleanups->getSubExpr();
2024 const auto *Ty = VD->getType().getTypePtr();
2029 if (TT->getDecl()->hasAttr<UnusedAttr>())
2035 if (
const auto *MTE = dyn_cast_if_present<MaterializeTemporaryExpr>(Init);
2036 MTE && MTE->getExtendingDecl()) {
2037 Ty = VD->getType().getNonReferenceType().getTypePtr();
2038 Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
2043 if (Ty->isIncompleteType() || Ty->isDependentType())
2048 Ty = Ty->getBaseElementTypeUnsafe();
2051 const TagDecl *Tag = TT->getDecl();
2052 if (Tag->
hasAttr<UnusedAttr>())
2055 if (
const auto *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2056 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>())
2060 const auto *Construct =
2061 dyn_cast<CXXConstructExpr>(Init->IgnoreImpCasts());
2062 if (Construct && !Construct->isElidable()) {
2064 if (!CD->
isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
2065 (VD->getInit()->isValueDependent() || !VD->evaluateValue()))
2071 if (Init->isTypeDependent()) {
2073 if (!Ctor->isTrivial())
2079 if (isa<CXXUnresolvedConstructExpr>(Init))
2093 if (isa<LabelDecl>(D)) {
2105 DiagnoseUnusedNestedTypedefs(
2114 for (
auto *TmpD : D->
decls()) {
2115 if (
const auto *
T = dyn_cast<TypedefNameDecl>(TmpD))
2116 DiagnoseUnusedDecl(
T, DiagReceiver);
2117 else if(
const auto *R = dyn_cast<RecordDecl>(TmpD))
2118 DiagnoseUnusedNestedTypedefs(R, DiagReceiver);
2133 if (
auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2136 UnusedLocalTypedefNameCandidates.insert(TD);
2144 if (isa<VarDecl>(D) && cast<VarDecl>(D)->isExceptionVariable())
2145 DiagID = diag::warn_unused_exception_param;
2146 else if (isa<LabelDecl>(D))
2147 DiagID = diag::warn_unused_label;
2149 DiagID = diag::warn_unused_variable;
2152 DiagReceiver(DiagLoc, PDiag(DiagID) << D << Hint <<
SourceRange(DiagLoc));
2168 if (Ty->isReferenceType() || Ty->isDependentType())
2172 const TagDecl *Tag = TT->getDecl();
2173 if (Tag->
hasAttr<UnusedAttr>())
2177 if (
const auto *RD = dyn_cast<CXXRecordDecl>(Tag);
2178 RD && !RD->hasAttr<WarnUnusedAttr>())
2185 if (VD->
hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType())
2191 if (VD->
hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType())
2194 auto iter = RefsMinusAssignments.find(VD);
2195 if (iter == RefsMinusAssignments.end())
2198 assert(iter->getSecond() >= 0 &&
2199 "Found a negative number of references to a VarDecl");
2200 if (
int RefCnt = iter->getSecond(); RefCnt > 0) {
2210 bool UnusedCXXCondDecl = VD->
isCXXCondDecl() && (RefCnt == 1);
2211 if (!UnusedCXXCondDecl)
2215 unsigned DiagID = isa<ParmVarDecl>(VD) ? diag::warn_unused_but_set_parameter
2216 : diag::warn_unused_but_set_variable;
2217 DiagReceiver(VD->
getLocation(), PDiag(DiagID) << VD);
2226 bool Diagnose =
false;
2230 Diagnose = L->
getStmt() ==
nullptr;
2239 if (S->decl_empty())
return;
2241 "Scope shouldn't contain decls!");
2248 std::optional<SourceLocation> PreviousDeclLoc;
2253 DeclDiags.push_back(LocAndDiag{Loc, std::nullopt, std::move(PD)});
2258 DeclDiags.push_back(LocAndDiag{Loc, PreviousDeclLoc, std::move(PD)});
2261 for (
auto *TmpD : S->decls()) {
2262 assert(TmpD &&
"This decl didn't get pushed??");
2264 assert(isa<NamedDecl>(TmpD) &&
"Decl isn't NamedDecl?");
2268 if (!S->hasUnrecoverableErrorOccurred()) {
2269 DiagnoseUnusedDecl(D, addDiag);
2270 if (
const auto *RD = dyn_cast<RecordDecl>(D))
2271 DiagnoseUnusedNestedTypedefs(RD, addDiag);
2272 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2273 DiagnoseUnusedButSetDecl(VD, addDiag);
2274 RefsMinusAssignments.erase(VD);
2281 if (
LabelDecl *LD = dyn_cast<LabelDecl>(D))
2286 IdResolver.RemoveDecl(D);
2287 auto ShadowI = ShadowingDecls.find(D);
2288 if (ShadowI != ShadowingDecls.end()) {
2289 if (
const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) {
2290 addDiagWithPrev(D->
getLocation(), FD->getLocation(),
2291 PDiag(diag::warn_ctor_parm_shadows_field)
2292 << D << FD << FD->getParent());
2294 ShadowingDecls.erase(ShadowI);
2298 llvm::sort(DeclDiags,
2299 [](
const LocAndDiag &LHS,
const LocAndDiag &RHS) ->
bool {
2304 return LHS.Loc.getRawEncoding() < RHS.Loc.getRawEncoding();
2306 for (
const LocAndDiag &D : DeclDiags) {
2308 if (D.PreviousDeclLoc)
2309 Diag(*D.PreviousDeclLoc, diag::note_previous_declaration);
2328 bool DoTypoCorrection) {
2331 NamedDecl *IDecl = LookupSingleName(TUScope,
Id, IdLoc, LookupOrdinaryName);
2333 if (!IDecl && DoTypoCorrection) {
2339 TUScope,
nullptr, CCC, CTK_ErrorRecovery)) {
2340 diagnoseTypo(C, PDiag(diag::err_undef_interface_suggest) <<
Id);
2377 (S->getEntity() && S->getEntity()->isTransparentContext()) ||
2378 (S->isClassScope() && !getLangOpts().
CPlusPlus))
2395 return "ucontext.h";
2397 llvm_unreachable(
"unhandled error kind");
2408 Parent->addDecl(CLinkageDecl);
2414 getCurFPFeatures().isFPConstrained(),
2417 New->
addAttr(BuiltinAttr::CreateImplicit(Context,
ID));
2423 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2426 FT->getParamType(i),
nullptr,
SC_None,
nullptr);
2428 Params.push_back(parm);
2430 New->setParams(Params);
2433 AddKnownFunctionAttributes(New);
2442 Scope *S,
bool ForRedeclaration,
2444 LookupNecessaryTypesForBuiltin(S,
ID);
2449 if (!ForRedeclaration)
2461 Diag(Loc, diag::warn_implicit_decl_no_jmp_buf)
2468 Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
2474 if (!ForRedeclaration &&
2477 Diag(Loc, LangOpts.C99 ? diag::ext_implicit_lib_function_decl_c99
2478 : diag::ext_implicit_lib_function_decl)
2481 Diag(Loc, diag::note_include_header_or_declare)
2489 RegisterLocallyScopedExternCDecl(New, S);
2497 PushOnScopeChains(New, TUScope);
2498 CurContext = SavedContext;
2518 while (
Filter.hasNext()) {
2527 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2529 Decl->getUnderlyingType()))
2534 if (OldTD->getAnonDeclWithTypedefName(
true) &&
2535 Decl->getAnonDeclWithTypedefName())
2548 OldType = OldTypedef->getUnderlyingType();
2555 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2556 Diag(New->
getLocation(), diag::err_redefinition_variably_modified_typedef)
2564 if (OldType != NewType &&
2568 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2570 <<
Kind << NewType << OldType;
2592 if (getLangOpts().ObjC) {
2594 switch (
TypeID->getLength()) {
2598 if (!
TypeID->isStr(
"id"))
2614 if (!
TypeID->isStr(
"Class"))
2621 if (!
TypeID->isStr(
"SEL"))
2648 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2649 auto *OldTag = OldTD->getAnonDeclWithTypedefName(
true);
2652 if (OldTag && NewTag &&
2653 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() &&
2654 !hasVisibleDefinition(OldTag, &Hidden)) {
2658 if (OldTD->isModed())
2660 OldTD->getUnderlyingType());
2665 makeMergedDefinitionVisible(Hidden);
2669 if (isa<EnumDecl>(NewTag)) {
2670 Scope *EnumScope = getNonFieldDeclScope(S);
2671 for (
auto *D : NewTag->decls()) {
2672 auto *ED = cast<EnumConstantDecl>(D);
2675 IdResolver.RemoveDecl(ED);
2676 ED->getLexicalDeclContext()->removeDecl(ED);
2684 if (isIncompatibleTypedef(Old, New))
2691 mergeDeclAttributes(New, Old);
2694 if (getLangOpts().MicrosoftExt)
2702 if (!isa<CXXRecordDecl>(CurContext))
2726 if (!isa<TypedefNameDecl>(Old))
2736 if (getLangOpts().Modules || getLangOpts().
C11)
2743 if (getDiagnostics().getSuppressSystemWarnings() &&
2758 const OwnershipAttr *OA = dyn_cast<OwnershipAttr>(A);
2759 const AnnotateAttr *Ann = dyn_cast<AnnotateAttr>(A);
2760 for (
const auto *i : D->
attrs())
2761 if (i->getKind() == A->
getKind()) {
2763 if (Ann->getAnnotation() == cast<AnnotateAttr>(i)->getAnnotation())
2768 if (OA && isa<OwnershipAttr>(i))
2769 return OA->getOwnKind() == cast<OwnershipAttr>(i)->getOwnKind();
2777 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
2778 return VD->isThisDeclarationADefinition();
2779 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
2780 return TD->isCompleteDefinition() || TD->isBeingDefined();
2791 AlignedAttr *OldAlignasAttr =
nullptr;
2792 AlignedAttr *OldStrictestAlignAttr =
nullptr;
2793 unsigned OldAlign = 0;
2801 if (I->isAlignmentDependent())
2807 unsigned Align = I->getAlignment(S.
Context);
2808 if (Align > OldAlign) {
2810 OldStrictestAlignAttr = I;
2815 AlignedAttr *NewAlignasAttr =
nullptr;
2816 unsigned NewAlign = 0;
2818 if (I->isAlignmentDependent())
2824 unsigned Align = I->getAlignment(S.
Context);
2825 if (Align > NewAlign)
2829 if (OldAlignasAttr && NewAlignasAttr && OldAlign != NewAlign) {
2837 if (OldAlign == 0 || NewAlign == 0) {
2839 if (
ValueDecl *VD = dyn_cast<ValueDecl>(New))
2850 if (OldAlign != NewAlign) {
2851 S.
Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch)
2854 S.
Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration);
2869 S.
Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration)
2873 bool AnyAdded =
false;
2876 if (OldAlign > NewAlign) {
2877 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.
Context);
2878 Clone->setInherited(
true);
2884 if (OldAlignasAttr && !NewAlignasAttr &&
2885 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) {
2886 AlignedAttr *Clone = OldAlignasAttr->clone(S.
Context);
2887 Clone->setInherited(
true);
2895 #define WANT_DECL_MERGE_LOGIC
2896 #include "clang/Sema/AttrParsedAttrImpl.inc"
2897 #undef WANT_DECL_MERGE_LOGIC
2904 if (!DiagnoseMutualExclusions(S, D,
Attr))
2915 if (
const auto *AA = dyn_cast<AvailabilityAttr>(
Attr))
2917 D, *AA, AA->getPlatform(), AA->
isImplicit(), AA->getIntroduced(),
2918 AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(),
2919 AA->getMessage(), AA->getStrict(), AA->getReplacement(), AMK,
2921 else if (
const auto *VA = dyn_cast<VisibilityAttr>(
Attr))
2923 else if (
const auto *VA = dyn_cast<TypeVisibilityAttr>(
Attr))
2925 else if (
const auto *ImportA = dyn_cast<DLLImportAttr>(
Attr))
2927 else if (
const auto *ExportA = dyn_cast<DLLExportAttr>(
Attr))
2929 else if (
const auto *EA = dyn_cast<ErrorAttr>(
Attr))
2931 else if (
const auto *FA = dyn_cast<FormatAttr>(
Attr))
2932 NewAttr = S.
mergeFormatAttr(D, *FA, FA->getType(), FA->getFormatIdx(),
2934 else if (
const auto *SA = dyn_cast<SectionAttr>(
Attr))
2936 else if (
const auto *CSA = dyn_cast<CodeSegAttr>(
Attr))
2938 else if (
const auto *IA = dyn_cast<MSInheritanceAttr>(
Attr))
2940 IA->getInheritanceModel());
2941 else if (
const auto *AA = dyn_cast<AlwaysInlineAttr>(
Attr))
2944 else if (S.
getLangOpts().CUDA && isa<FunctionDecl>(D) &&
2945 (isa<CUDAHostAttr>(
Attr) || isa<CUDADeviceAttr>(
Attr) ||
2946 isa<CUDAGlobalAttr>(
Attr))) {
2950 }
else if (
const auto *MA = dyn_cast<MinSizeAttr>(
Attr))
2952 else if (
const auto *SNA = dyn_cast<SwiftNameAttr>(
Attr))
2954 else if (
const auto *OA = dyn_cast<OptimizeNoneAttr>(
Attr))
2956 else if (
const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(
Attr))
2958 else if (isa<AlignedAttr>(
Attr))
2962 else if ((isa<DeprecatedAttr>(
Attr) || isa<UnavailableAttr>(
Attr)) &&
2967 else if (
const auto *UA = dyn_cast<UuidAttr>(
Attr))
2968 NewAttr = S.
mergeUuidAttr(D, *UA, UA->getGuid(), UA->getGuidDecl());
2969 else if (
const auto *IMA = dyn_cast<WebAssemblyImportModuleAttr>(
Attr))
2971 else if (
const auto *INA = dyn_cast<WebAssemblyImportNameAttr>(
Attr))
2973 else if (
const auto *A = dyn_cast<SYCLIntelLoopFuseAttr>(
Attr))
2975 else if (
const auto *TCBA = dyn_cast<EnforceTCBAttr>(
Attr))
2977 else if (
const auto *TCBLA = dyn_cast<EnforceTCBLeafAttr>(
Attr))
2979 else if (
const auto *A = dyn_cast<IntelReqdSubGroupSizeAttr>(
Attr))
2981 else if (
const auto *A = dyn_cast<IntelNamedSubGroupSizeAttr>(
Attr))
2983 else if (
const auto *A = dyn_cast<SYCLIntelNumSimdWorkItemsAttr>(
Attr))
2985 else if (
const auto *A = dyn_cast<SYCLIntelESimdVectorizeAttr>(
Attr))
2987 else if (
const auto *A = dyn_cast<SYCLIntelSchedulerTargetFmaxMhzAttr>(
Attr))
2989 else if (
const auto *A = dyn_cast<SYCLIntelNoGlobalWorkOffsetAttr>(
Attr))
2991 else if (
const auto *A = dyn_cast<SYCLIntelMaxReplicatesAttr>(
Attr))
2993 else if (
const auto *A = dyn_cast<SYCLIntelMaxConcurrencyAttr>(
Attr))
2995 else if (
const auto *A = dyn_cast<SYCLIntelForcePow2DepthAttr>(
Attr))
2997 else if (
const auto *A = dyn_cast<SYCLIntelInitiationIntervalAttr>(
Attr))
2999 else if (
const auto *A = dyn_cast<SYCLWorkGroupSizeHintAttr>(
Attr))
3001 else if (
const auto *A =
3002 dyn_cast<SYCLIntelMinWorkGroupsPerComputeUnitAttr>(
Attr))
3004 else if (
const auto *A =
3005 dyn_cast<SYCLIntelMaxWorkGroupsPerMultiprocessorAttr>(
Attr))
3007 else if (
const auto *A = dyn_cast<SYCLIntelMaxGlobalWorkDimAttr>(
Attr))
3009 else if (
const auto *BTFA = dyn_cast<BTFDeclTagAttr>(
Attr))
3011 else if (
const auto *A = dyn_cast<SYCLIntelBankWidthAttr>(
Attr))
3013 else if (
const auto *A = dyn_cast<SYCLIntelNumBanksAttr>(
Attr))
3015 else if (
const auto *A = dyn_cast<SYCLDeviceHasAttr>(
Attr))
3017 else if (
const auto *A = dyn_cast<SYCLUsesAspectsAttr>(
Attr))
3019 else if (
const auto *A = dyn_cast<SYCLTypeAttr>(
Attr))
3021 else if (
const auto *A = dyn_cast<SYCLIntelPipeIOAttr>(
Attr))
3023 else if (
const auto *A = dyn_cast<SYCLIntelMaxWorkGroupSizeAttr>(
Attr))
3025 else if (
const auto *A = dyn_cast<SYCLAddIRAttributesFunctionAttr>(
Attr))
3027 else if (
const auto *A =
3028 dyn_cast<SYCLAddIRAttributesKernelParameterAttr>(
Attr))
3030 else if (
const auto *A =
3031 dyn_cast<SYCLAddIRAttributesGlobalVariableAttr>(
Attr))
3033 else if (
const auto *A = dyn_cast<SYCLAddIRAnnotationsMemberAttr>(
Attr))
3035 else if (
const auto *A = dyn_cast<SYCLReqdWorkGroupSizeAttr>(
Attr))
3037 else if (
const auto *NT = dyn_cast<HLSLNumThreadsAttr>(
Attr))
3040 else if (
const auto *SA = dyn_cast<HLSLShaderAttr>(
Attr))
3042 else if (isa<SuppressAttr>(
Attr))
3051 if (isa<MSInheritanceAttr>(NewAttr))
3060 if (
const TagDecl *TD = dyn_cast<TagDecl>(D))
3061 return TD->getDefinition();
3062 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
3068 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
3070 if (FD->isDefined(Def,
true))
3077 for (
const auto *Attribute : D->
attrs())
3078 if (Attribute->getKind() ==
Kind)
3090 if (!Def || Def == New)
3094 for (
unsigned I = 0, E = NewAttributes.size(); I != E;) {
3095 const Attr *NewAttribute = NewAttributes[I];
3097 if (isa<AliasAttr>(NewAttribute) || isa<IFuncAttr>(NewAttribute)) {
3104 NewAttributes.erase(NewAttributes.begin() + I);
3109 VarDecl *VD = cast<VarDecl>(New);
3110 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() ==
3112 ? diag::err_alias_after_tentative
3113 : diag::err_redefinition;
3115 if (
Diag == diag::err_redefinition)
3125 if (
const VarDecl *VD = dyn_cast<VarDecl>(Def)) {
3138 if (isa<C11NoReturnAttr>(NewAttribute)) {
3142 }
else if (isa<UuidAttr>(NewAttribute)) {
3146 }
else if (
const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) {
3147 if (AA->isAlignas()) {
3158 S.
Diag(NewAttribute->
getLocation(), diag::note_alignas_on_declaration)
3160 NewAttributes.erase(NewAttributes.begin() + I);
3164 }
else if (isa<LoaderUninitializedAttr>(NewAttribute)) {
3170 diag::err_loader_uninitialized_redeclaration);
3172 NewAttributes.erase(NewAttributes.begin() + I);
3176 }
else if (isa<SelectAnyAttr>(NewAttribute) &&
3177 cast<VarDecl>(New)->isInline() &&
3178 !cast<VarDecl>(New)->isInlineSpecified()) {
3185 }
else if (isa<OMPDeclareVariantAttr>(NewAttribute)) {
3193 diag::warn_attribute_precede_definition);
3195 NewAttributes.erase(NewAttributes.begin() + I);
3201 const ConstInitAttr *CIAttr,
3202 bool AttrBeforeInit) {
3209 std::string SuitableSpelling;
3211 SuitableSpelling = std::string(
3213 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3215 InsertLoc, {tok::l_square, tok::l_square,
3216 S.PP.getIdentifierInfo(
"clang"), tok::coloncolon,
3217 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3218 tok::r_square, tok::r_square}));
3219 if (SuitableSpelling.empty())
3221 InsertLoc, {tok::kw___attribute, tok::l_paren, tok::r_paren,
3222 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3223 tok::r_paren, tok::r_paren}));
3224 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus20)
3225 SuitableSpelling =
"constinit";
3226 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3227 SuitableSpelling =
"[[clang::require_constant_initialization]]";
3228 if (SuitableSpelling.empty())
3229 SuitableSpelling =
"__attribute__((require_constant_initialization))";
3230 SuitableSpelling +=
" ";
3232 if (AttrBeforeInit) {
3235 assert(CIAttr->isConstinit() &&
"should not diagnose this for attribute");
3238 S.
Diag(CIAttr->getLocation(), diag::note_constinit_specified_here);
3242 S.
Diag(CIAttr->getLocation(),
3243 CIAttr->isConstinit() ? diag::err_constinit_added_too_late
3244 : diag::warn_require_const_init_added_too_late)
3247 << CIAttr->isConstinit()
3256 UsedAttr *NewAttr = OldAttr->clone(Context);
3257 NewAttr->setInherited(
true);
3261 RetainAttr *NewAttr = OldAttr->clone(Context);
3262 NewAttr->setInherited(
true);
3272 const auto *OldConstInit = Old->
getAttr<ConstInitAttr>();
3273 const auto *NewConstInit = New->
getAttr<ConstInitAttr>();
3274 if (
bool(OldConstInit) !=
bool(NewConstInit)) {
3275 const auto *OldVD = cast<VarDecl>(Old);
3276 auto *NewVD = cast<VarDecl>(New);
3282 (NewVD->hasInit() || NewVD->isThisDeclarationADefinition()))
3285 if (InitDecl == NewVD) {
3289 if (OldConstInit && OldConstInit->isConstinit())
3292 }
else if (NewConstInit) {
3296 if (InitDecl && InitDecl != NewVD) {
3299 NewVD->dropAttr<ConstInitAttr>();
3307 if (AsmLabelAttr *NewA = New->
getAttr<AsmLabelAttr>()) {
3308 if (AsmLabelAttr *OldA = Old->
getAttr<AsmLabelAttr>()) {
3309 if (!OldA->isEquivalent(NewA)) {
3312 Diag(OldA->getLocation(), diag::note_previous_declaration);
3314 }
else if (Old->
isUsed()) {
3318 << isa<FunctionDecl>(Old) << New->
getAttr<AsmLabelAttr>()->
getRange();
3323 if (
const auto *NewAbiTagAttr = New->
getAttr<AbiTagAttr>()) {
3324 if (
const auto *OldAbiTagAttr = Old->
getAttr<AbiTagAttr>()) {
3325 for (
const auto &NewTag : NewAbiTagAttr->tags()) {
3326 if (!llvm::is_contained(OldAbiTagAttr->tags(), NewTag)) {
3327 Diag(NewAbiTagAttr->getLocation(),
3328 diag::err_new_abi_tag_on_redeclaration)
3330 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
3334 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
3340 if (New->
hasAttr<SectionAttr>() && !Old->
hasAttr<SectionAttr>()) {
3341 if (
auto *VD = dyn_cast<VarDecl>(New)) {
3343 Diag(New->
getLocation(), diag::warn_attribute_section_on_redeclaration);
3350 const auto *NewCSA = New->
getAttr<CodeSegAttr>();
3351 if (NewCSA && !Old->
hasAttr<CodeSegAttr>() &&
3352 !NewCSA->isImplicit() && isa<CXXMethodDecl>(New)) {
3370 if (isa<DeprecatedAttr>(I) ||
3371 isa<UnavailableAttr>(I) ||
3372 isa<AvailabilityAttr>(I)) {
3377 case AMK_Redeclaration:
3379 case AMK_ProtocolImplementation:
3380 case AMK_OptionalProtocolImplementation:
3387 if (isa<UsedAttr>(I) || isa<RetainAttr>(I))
3409 const CarriesDependencyAttr *CDA = newDecl->
getAttr<CarriesDependencyAttr>();
3410 if (CDA && !oldDecl->
hasAttr<CarriesDependencyAttr>()) {
3411 S.
Diag(CDA->getLocation(),
3412 diag::err_carries_dependency_missing_on_first_decl) << 1;
3420 diag::note_carries_dependency_missing_first_decl) << 1;
3428 const auto *NDAttr = newDecl->
getAttr<HLSLParamModifierAttr>();
3429 const auto *ODAttr = oldDecl->
getAttr<HLSLParamModifierAttr>();
3434 if (NDAttr && ODAttr &&
3435 NDAttr->getSpellingListIndex() != ODAttr->getSpellingListIndex()) {
3436 S.
Diag(newDecl->
getLocation(), diag::err_hlsl_param_qualifier_mismatch)
3437 << NDAttr << newDecl;
3446 bool foundAny = newDecl->
hasAttrs();
3455 cast<InheritableParamAttr>(I->clone(S.
Context));
3468 auto NoSizeInfo = [&Ctx](
QualType Ty) {
3469 if (Ty->isIncompleteArrayType() || Ty->isPointerType())
3477 if (NoSizeInfo(Old) && NoSizeInfo(New))
3509 if (*Oldnullability != *Newnullability) {
3510 S.
Diag(NewParam->
getLocation(), diag::warn_mismatched_nullability_attr)
3529 const auto *OldParamDT = dyn_cast<DecayedType>(OldParam->
getType());
3530 const auto *NewParamDT = dyn_cast<DecayedType>(NewParam->
getType());
3531 if (OldParamDT && NewParamDT &&
3532 OldParamDT->getPointeeType() == NewParamDT->getPointeeType()) {
3533 QualType OldParamOT = OldParamDT->getOriginalType();
3534 QualType NewParamOT = NewParamDT->getOriginalType();
3537 << NewParam << NewParamOT;
3548 struct GNUCompatibleParamWarning {
3558 template <
typename T>
3559 static std::pair<diag::kind, SourceLocation>
3563 if (Old->isThisDeclarationADefinition())
3564 PrevDiag = diag::note_previous_definition;
3565 else if (Old->isImplicit()) {
3566 PrevDiag = diag::note_previous_implicit_declaration;
3567 if (
const auto *FD = dyn_cast<FunctionDecl>(Old)) {
3568 if (FD->getBuiltinID())
3569 PrevDiag = diag::note_previous_builtin_declaration;
3572 OldLocation = New->getLocation();
3574 PrevDiag = diag::note_previous_declaration;
3575 return std::make_pair(PrevDiag, OldLocation);
3583 return ((FD->
hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) &&
3584 !LangOpts.CPlusPlus &&
3596 template <
typename T>
3610 template<
typename T>
static bool isExternC(
T *D) {
return D->isExternC(); }
3617 template<
typename ExpectedDecl>
3639 !Old->getDeclContext()->getRedeclContext()->Equals(
3640 New->getDeclContext()->getRedeclContext()) &&
3645 S.
Diag(New->getLocation(), diag::err_using_decl_conflict_reverse);
3658 const auto *AttrA = A->
getAttr<PassObjectSizeAttr>();
3659 const auto *AttrB = B->
getAttr<PassObjectSizeAttr>();
3662 return AttrA && AttrB && AttrA->getType() == AttrB->getType() &&
3663 AttrA->isDynamic() == AttrB->isDynamic();
3689 if (NamedDC->Equals(SemaDC))
3692 assert((NamedDC->InEnclosingNamespaceSetOf(SemaDC) ||
3694 "unexpected context for redeclaration");
3705 if (
auto *FD = dyn_cast<FunctionDecl>(NewD))
3706 FixSemaDC(FD->getDescribedFunctionTemplate());
3707 else if (
auto *VD = dyn_cast<VarDecl>(NewD))
3708 FixSemaDC(VD->getDescribedVarTemplate());
3723 bool MergeTypeWithOld,
bool NewDeclIsDefn) {
3730 Diag(Shadow->getTargetDecl()->getLocation(),
3731 diag::note_using_decl_target);
3732 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
3741 if (checkUsingShadowRedecl<FunctionTemplateDecl>(*
this, Shadow,
3744 OldD = Old = cast<FunctionTemplateDecl>(Shadow->getTargetDecl())
3747 if (checkUsingShadowRedecl<FunctionDecl>(*
this, Shadow, New))
3749 OldD = Old = cast<FunctionDecl>(Shadow->getTargetDecl());
3768 if (!getASTContext().canBuiltinBeRedeclared(Old)) {
3777 std::tie(PrevDiag, OldLocation) =
3784 if (!isa<CXXMethodDecl>(New) && !isa<CXXMethodDecl>(Old) &&
3789 if (getLangOpts().MicrosoftExt) {
3791 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3794 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3799 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
3800 if (!Old->
hasAttr<InternalLinkageAttr>()) {
3804 New->
dropAttr<InternalLinkageAttr>();
3807 if (
auto *EA = New->
getAttr<ErrorAttr>()) {
3808 if (!Old->
hasAttr<ErrorAttr>()) {
3809 Diag(EA->getLocation(), diag::err_attribute_missing_on_first_decl) << EA;
3815 if (CheckRedeclarationInModule(New, Old))
3818 if (!getLangOpts().CPlusPlus) {
3819 bool OldOvl = Old->
hasAttr<OverloadableAttr>();
3830 const Decl *DiagOld = Old;
3832 auto OldIter = llvm::find_if(Old->
redecls(), [](
const Decl *D) {
3833 const auto *A = D->getAttr<OverloadableAttr>();
3834 return A && !A->isImplicit();
3838 DiagOld = OldIter == Old->
redecls_end() ? nullptr : *OldIter;
3843 diag::note_attribute_overloadable_prev_overload)
3847 New->
addAttr(OverloadableAttr::CreateImplicit(Context));
3855 if (IsInvalidSMECallConversion(Old->
getType(), New->
getType())) {
3858 Diag(OldLocation, diag::note_previous_declaration);
3877 const FunctionType *OldType = cast<FunctionType>(OldQType);
3878 const FunctionType *NewType = cast<FunctionType>(NewQType);
3881 bool RequiresAdjustment =
false;
3883 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC()) {
3888 bool NewCCExplicit = getCallingConvAttributedType(New->
getType());
3889 if (!NewCCExplicit) {
3893 RequiresAdjustment =
true;
3903 << (
int)CallingConventionIgnoredReason::BuiltinFunction;
3905 RequiresAdjustment =
true;
3908 bool FirstCCExplicit = getCallingConvAttributedType(
First->getType());
3912 << (!FirstCCExplicit ?
"" :
3916 Diag(
First->getLocation(), diag::note_previous_declaration);
3924 RequiresAdjustment =
true;
3934 Diag(OldLocation, diag::note_previous_declaration);
3939 RequiresAdjustment =
true;
3946 <<
"'ns_returns_retained'";
3947 Diag(OldLocation, diag::note_previous_declaration);
3952 RequiresAdjustment =
true;
3958 AnyX86NoCallerSavedRegistersAttr *
Attr =
3959 New->
getAttr<AnyX86NoCallerSavedRegistersAttr>();
3961 Diag(OldLocation, diag::note_previous_declaration);
3966 RequiresAdjustment =
true;
3969 if (RequiresAdjustment) {
3979 !New->
hasAttr<GNUInlineAttr>() &&
3980 !getLangOpts().GNUInline &&
3988 if (New->
hasAttr<GNUInlineAttr>() &&
3999 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4014 if (!Context.
hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) &&
4015 canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType,
4016 OldDeclaredReturnType)) {
4024 Diag(New->
getLocation(), diag::err_member_def_does_not_match_ret_type)
4029 Diag(OldLocation, PrevDiag) << Old << Old->
getType()
4038 QualType NewReturnType = cast<FunctionType>(NewQType)->getReturnType();
4039 if (OldReturnType != NewReturnType) {
4055 const CXXMethodDecl *OldMethod = dyn_cast<CXXMethodDecl>(Old);
4057 if (OldMethod && NewMethod) {
4064 bool IsClassScopeExplicitSpecialization =
4070 !IsClassScopeExplicitSpecialization) {
4076 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4084 if (!inTemplateInstantiation()) {
4086 if (isa<CXXConstructorDecl>(OldMethod))
4087 NewDiag = diag::err_constructor_redeclared;
4088 else if (isa<CXXDestructorDecl>(NewMethod))
4089 NewDiag = diag::err_destructor_redeclared;
4090 else if (isa<CXXConversionDecl>(NewMethod))
4091 NewDiag = diag::err_conv_function_redeclared;
4093 NewDiag = diag::err_member_redeclared;
4097 Diag(New->
getLocation(), diag::err_member_redeclared_in_instantiation)
4100 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4113 diag::err_definition_of_implicitly_declared_member)
4114 << New << llvm::to_underlying(getSpecialMember(OldMethod));
4119 diag::err_definition_of_explicitly_defaulted_member)
4120 << llvm::to_underlying(getSpecialMember(OldMethod));
4135 if (CheckEquivalentExceptionSpec(Old, New))
4142 if (
const auto *NRA = New->
getAttr<CXX11NoReturnAttr>())
4143 if (!Old->
hasAttr<CXX11NoReturnAttr>()) {
4144 Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl)
4153 const CarriesDependencyAttr *CDA = New->
getAttr<CarriesDependencyAttr>();
4154 if (CDA && !Old->
hasAttr<CarriesDependencyAttr>()) {
4155 Diag(CDA->getLocation(),
4156 diag::err_carries_dependency_missing_on_first_decl) << 0;
4158 diag::note_carries_dependency_missing_first_decl) << 0;
4167 QualType OldQTypeForComparison = OldQType;
4172 OldQTypeForComparison =
QualType(OldTypeForComparison, 0);
4187 Diag(OldLocation, PrevDiag);
4189 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4190 Diag(OldLocation, PrevDiag);
4201 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
4206 if (!canFullyTypeCheckRedeclaration(New, Old, NewQType, OldQType))
4261 bool IsWithoutProtoADef =
false, IsWithProtoADef =
false;
4262 if (WithoutProto == New)
4263 IsWithoutProtoADef = NewDeclIsDefn;
4265 IsWithProtoADef = NewDeclIsDefn;
4267 diag::warn_non_prototype_changes_behavior)
4268 << IsWithoutProtoADef << (WithoutProto->
getNumParams() ? 0 : 1)
4269 << (WithoutProto == Old) << IsWithProtoADef;
4279 !IsWithoutProtoADef)
4289 if (MergeTypeWithOld && isa<FunctionNoProtoType>(NewFuncType) &&
4290 (OldProto = dyn_cast<FunctionProtoType>(OldFuncType))) {
4293 assert(!OldProto->hasExceptionSpec() &&
"Exception spec in C");
4295 OldProto->getParamTypes(),
4296 OldProto->getExtProtoInfo());
4302 for (
const auto &ParamType : OldProto->param_types()) {
4305 ParamType,
nullptr,
SC_None,
nullptr);
4308 Params.push_back(Param);
4311 New->setParams(Params);
4314 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
4347 NewProto->getReturnType());
4348 bool LooseCompatible = !MergedReturn.
isNull();
4350 LooseCompatible && Idx !=
End; ++Idx) {
4354 NewProto->getParamType(Idx))) {
4355 ArgTypes.push_back(NewParm->
getType());
4359 GNUCompatibleParamWarning Warn = { OldParm, NewParm,
4360 NewProto->getParamType(Idx) };
4361 Warnings.push_back(Warn);
4362 ArgTypes.push_back(NewParm->
getType());
4364 LooseCompatible =
false;
4367 if (LooseCompatible) {
4368 for (
unsigned Warn = 0; Warn < Warnings.size(); ++Warn) {
4369 Diag(Warnings[Warn].NewParm->getLocation(),
4370 diag::ext_param_promoted_not_compatible_with_prototype)
4371 << Warnings[Warn].PromotedType
4372 << Warnings[Warn].OldParm->getType();
4373 if (Warnings[Warn].OldParm->getLocation().isValid())
4374 Diag(Warnings[Warn].OldParm->getLocation(),
4375 diag::note_previous_declaration);
4378 if (MergeTypeWithOld)
4381 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
4398 Diag(OldLocation, diag::note_previous_builtin_declaration)
4403 PrevDiag = diag::note_previous_builtin_declaration;
4407 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4421 Scope *S,
bool MergeTypeWithOld) {
4423 mergeDeclAttributes(New, Old);
4436 for (
unsigned i = 0, e = New->
getNumParams(); i != e; ++i) {
4444 return MergeCXXFunctionDecl(New, Old, S);
4450 if (!Merged.isNull() && MergeTypeWithOld)
4461 ? (oldMethod->
isOptional() ? AMK_OptionalProtocolImplementation
4462 : AMK_ProtocolImplementation)
4463 : isa<ObjCImplDecl>(newMethod->
getDeclContext()) ? AMK_Redeclaration
4466 mergeDeclAttributes(newMethod, oldMethod, MergeKind);
4473 ni != ne && oi != oe; ++ni, ++oi)
4476 CheckObjCMethodOverride(newMethod, oldMethod);
4483 ? diag::err_redefinition_different_type
4484 : diag::err_redeclaration_different_type)
4489 std::tie(PrevDiag, OldLocation)
4491 S.
Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4503 bool MergeTypeWithOld) {
4514 return MergeVarDeclExceptionSpecs(New, Old);
4531 QualType PrevVDTy = PrevVD->getType();
4585 if (MergeTypeWithOld)
4631 if (!shouldLinkPossiblyHiddenDecl(
Previous, New))
4641 OldTemplate = dyn_cast<VarTemplateDecl>(
Previous.getFoundDecl());
4645 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4646 if (checkUsingShadowRedecl<VarTemplateDecl>(*
this, Shadow, NewTemplate))
4649 Old = dyn_cast<VarDecl>(
Previous.getFoundDecl());
4652 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4653 if (checkUsingShadowRedecl<VarDecl>(*
this, Shadow, New))
4660 notePreviousDefinition(
Previous.getRepresentativeDecl(),
4673 true, TPL_TemplateMatch))
4687 mergeDeclAttributes(New, Old);
4690 if (New->
hasAttr<WeakImportAttr>() &&
4692 !Old->
hasAttr<WeakImportAttr>()) {
4699 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
4700 if (!Old->
hasAttr<InternalLinkageAttr>()) {
4704 New->
dropAttr<InternalLinkageAttr>();
4709 if (MostRecent != Old) {
4710 MergeVarDeclTypes(New, MostRecent,
4722 std::tie(PrevDiag, OldLocation) =
4729 if (getLangOpts().MicrosoftExt) {
4732 Diag(OldLocation, PrevDiag);
4736 Diag(OldLocation, PrevDiag);
4755 Diag(OldLocation, PrevDiag);
4763 Diag(OldLocation, PrevDiag);
4769 Diag(OldLocation, PrevDiag);
4773 if (CheckRedeclarationInModule(New, Old))
4785 Diag(OldLocation, PrevDiag);
4795 Diag(Def->getLocation(), diag::note_previous_definition);
4809 Diag(OldLocation, PrevDiag);
4812 Diag(OldLocation, PrevDiag);
4820 Diag(OldLocation, PrevDiag);
4830 diag::warn_deprecated_redundant_constexpr_static_def);
4833 if (Def && checkVarDeclRedefinition(Def, New))
4839 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4840 Diag(OldLocation, PrevDiag);
4869 auto &HSI = PP.getHeaderSearchInfo();
4870 StringRef HdrFilename =
4873 auto noteFromModuleOrInclude = [&](
Module *Mod,
4879 if (IncLoc.isValid()) {
4881 Diag(IncLoc, diag::note_redefinition_modules_same_file)
4887 Diag(IncLoc, diag::note_redefinition_include_same_file)
4888 << HdrFilename.str();
4898 if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
4903 EmittedDiag |= noteFromModuleOrInclude(getCurrentModule(), NewIncLoc);
4906 if (FOld && !HSI.isFileMultipleIncludeGuarded(*FOld))
4921 if (!hasVisibleDefinition(Old) &&
4923 isa<VarTemplateSpecializationDecl>(New) ||
4932 makeMergedDefinitionVisible(OldTD);
4933 makeMergedDefinitionVisible(Old);
4949 return ParsedFreeStandingDeclSpec(
4961 ? S->getMSCurManglingNumber()
4962 : S->getMSLastManglingNumber();
4969 if (isa<CXXRecordDecl>(Tag->
getParent())) {
4984 Decl *ManglingContextDecl;
4985 std::tie(MCtx, ManglingContextDecl) =
4995 struct NonCLikeKind {
5007 explicit operator bool() {
return Kind != None; }
5015 return {NonCLikeKind::Invalid, {}};
5022 return {NonCLikeKind::BaseClass,
5025 bool Invalid =
false;
5034 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
5035 if (FD->hasInClassInitializer()) {
5036 auto *Init = FD->getInClassInitializer();
5037 return {NonCLikeKind::DefaultMemberInit,
5045 if (isa<FriendDecl>(D))
5050 if (isa<StaticAssertDecl>(D) || isa<IndirectFieldDecl>(D) ||
5053 auto *MemberRD = dyn_cast<CXXRecordDecl>(D);
5061 if (MemberRD->isLambda())
5062 return {NonCLikeKind::Lambda, MemberRD->getSourceRange()};
5066 if (MemberRD->isThisDeclarationADefinition()) {
5102 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(TagFromDeclSpec);
5106 if (NonCLike || ChangesLinkage) {
5107 if (NonCLike.Kind == NonCLikeKind::Invalid)
5110 unsigned DiagID = diag::ext_non_c_like_anon_struct_in_typedef;
5111 if (ChangesLinkage) {
5114 DiagID = diag::err_typedef_changes_linkage;
5116 DiagID = diag::err_non_c_like_anon_struct_in_typedef;
5122 TextToInsert +=
' ';
5125 Diag(FixitLoc, DiagID)
5126 << isa<TypeAliasDecl>(NewTD)
5129 Diag(NonCLike.Range.getBegin(), diag::note_non_c_like_anon_struct)
5130 << NonCLike.Kind - 1 << NonCLike.Range;
5133 << NewTD << isa<TypeAliasDecl>(NewTD);
5155 if (
const auto *ED = dyn_cast<EnumDecl>(DS.
getRepAsDecl())) {
5156 if (ED->isScopedUsingClassTag())
5163 llvm_unreachable(
"unexpected type specifier");
5173 bool IsExplicitInstantiation,
5175 Decl *TagD =
nullptr;
5190 if (isa<TagDecl>(TagD))
5191 Tag = cast<TagDecl>(TagD);
5193 Tag = CTD->getTemplatedDecl();
5197 handleTagNumbering(Tag, S);
5208 diag::err_typecheck_invalid_restrict_not_pointer_noarg)
5214 << getLangOpts().CPlusPlus17;
5225 else if (getLangOpts().C23)
5234 DiagnoseFunctionSpecifiers(DS);
5241 return ActOnFriendTypeDecl(S, DS, TemplateParams);
5245 bool DeclaresAnything =
true;
5249 if (!
Record->getDeclName() &&
Record->isCompleteDefinition() &&
5252 Record->getDeclContext()->isRecord()) {
5260 if (CurContext->isFunctionOrMethod())
5262 return BuildAnonymousStructOrUnion(S, DS, AS,
Record,
5266 DeclaresAnything =
false;
5276 if (!getLangOpts().
CPlusPlus && CurContext->isRecord() &&
5289 Record = dyn_cast<RecordDecl>(Tag);
5296 if (
Record && getLangOpts().MicrosoftExt) {
5299 return BuildMicrosoftCAnonymousStruct(S, DS,
Record);
5302 DeclaresAnything =
false;
5313 if (
EnumDecl *Enum = dyn_cast_or_null<EnumDecl>(Tag))
5314 if (Enum->enumerator_begin() == Enum->enumerator_end() &&
5315 !Enum->getIdentifier() && !Enum->isInvalidDecl())
5316 DeclaresAnything =
false;
5324 DeclaresAnything =
false;
5333 ActOnDocumentableDecl(TagD);
5343 if (!DeclaresAnything) {
5346 Diag(DS.
getBeginLoc(), (IsExplicitInstantiation || !TemplateParams.empty())
5347 ? diag::err_no_declarators
5348 : diag::ext_no_declarators)
5361 unsigned DiagID = diag::warn_standalone_specifier;
5363 DiagID = diag::ext_standalone_specifier;
5404 auto EmitAttributeDiagnostic = [
this, &DS](
const ParsedAttr &AL) {
5405 unsigned DiagnosticId = diag::warn_declspec_attribute_ignored;
5406 if (AL.isAlignas() && !getLangOpts().CPlusPlus)
5407 DiagnosticId = diag::warn_attribute_ignored;
5408 else if (AL.isRegularKeywordAttribute())
5409 DiagnosticId = diag::err_declspec_keyword_has_no_effect;
5411 DiagnosticId = diag::warn_declspec_attribute_ignored;
5412 Diag(AL.getLoc(), DiagnosticId)
5416 llvm::for_each(DS.
getAttributes(), EmitAttributeDiagnostic);
5417 llvm::for_each(DeclAttrs, EmitAttributeDiagnostic);
5441 assert(PrevDecl &&
"Expected a non-null Decl");
5454 SemaRef.
Diag(NameLoc, diag::err_anonymous_record_member_redecl)
5456 SemaRef.
Diag(PrevDecl->
getLocation(), diag::note_previous_declaration);
5462 if (
auto *RD = dyn_cast_if_present<RecordDecl>(D))
5463 DiagPlaceholderFieldDeclDefinitions(RD);
5476 if (
Record->isAnonymousStructOrUnion())
5481 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
5487 DiagPlaceholderVariableDefinition(ND->
getLocation());
5512 bool Invalid =
false;
5515 for (
auto *D : AnonRecord->
decls()) {
5516 if ((isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) &&
5517 cast<NamedDecl>(D)->getDeclName()) {
5533 unsigned OldChainingSize = Chaining.size();
5535 Chaining.append(IF->chain_begin(), IF->chain_end());
5537 Chaining.push_back(VD);
5539 assert(Chaining.size() >= 2);
5542 for (
unsigned i = 0; i < Chaining.size(); i++)
5543 NamedChain[i] = Chaining[i];
5547 VD->
getType(), {NamedChain, Chaining.size()});
5559 Chaining.resize(OldChainingSize);
5574 "Parser allowed 'typedef' as storage class VarDecl.");
5575 switch (StorageClassSpec) {
5589 llvm_unreachable(
"unknown storage class specifier");
5593 assert(
Record->hasInClassInitializer());
5595 for (
const auto *I :
Record->decls()) {
5596 const auto *FD = dyn_cast<FieldDecl>(I);
5597 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
5598 FD = IFD->getAnonField();
5599 if (FD && FD->hasInClassInitializer())
5600 return FD->getLocation();
5603 llvm_unreachable(
"couldn't find in-class initializer");
5608 if (!
Parent->isUnion() || !
Parent->hasInClassInitializer())
5611 S.
Diag(DefaultInitLoc, diag::err_multiple_mem_union_initialization);
5617 if (!
Parent->isUnion() || !
Parent->hasInClassInitializer())
5635 Diag(
Record->getLocation(), diag::ext_anonymous_union);
5637 Diag(
Record->getLocation(), diag::ext_gnu_anonymous_struct);
5638 else if (!
Record->isUnion() && !getLangOpts().
C11)
5639 Diag(
Record->getLocation(), diag::ext_c11_anonymous_struct);
5643 bool Invalid =
false;
5645 const char *PrevSpec =
nullptr;
5656 !cast<NamespaceDecl>(OwnerScope)->isAnonymousNamespace()))) {
5657 Diag(
Record->getLocation(), diag::err_anonymous_union_not_static)
5662 PrevSpec, DiagID, Policy);
5668 isa<RecordDecl>(Owner)) {
5670 diag::err_anonymous_union_with_storage_spec)
5684 <<
Record->isUnion() <<
"const"
5688 diag::ext_anonymous_struct_union_qualified)
5689 <<
Record->isUnion() <<
"volatile"
5693 diag::ext_anonymous_struct_union_qualified)
5694 <<
Record->isUnion() <<
"restrict"
5698 diag::ext_anonymous_struct_union_qualified)
5699 <<
Record->isUnion() <<
"_Atomic"
5703 diag::ext_anonymous_struct_union_qualified)
5704 <<
Record->isUnion() <<
"__unaligned"
5714 for (
auto *Mem :
Record->decls()) {
5716 if (Mem->isInvalidDecl())
5719 if (
auto *FD = dyn_cast<FieldDecl>(Mem)) {
5723 assert(FD->getAccess() !=
AS_none);
5725 Diag(FD->getLocation(), diag::err_anonymous_record_nonpublic_member)
5735 if (CheckNontrivialField(FD))
5737 }
else if (Mem->isImplicit()) {
5739 }
else if (isa<TagDecl>(Mem) && Mem->getDeclContext() !=
Record) {
5744 }
else if (
auto *MemRecord = dyn_cast<RecordDecl>(Mem)) {
5745 if (!MemRecord->isAnonymousStructOrUnion() &&
5746 MemRecord->getDeclName()) {
5748 if (getLangOpts().MicrosoftExt)
5749 Diag(MemRecord->getLocation(), diag::ext_anonymous_record_with_type)
5753 Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type)
5761 Diag(MemRecord->getLocation(),
5762 diag::ext_anonymous_record_with_anonymous_type)
5765 }
else if (isa<AccessSpecDecl>(Mem)) {
5767 }
else if (isa<StaticAssertDecl>(Mem)) {
5772 unsigned DK = diag::err_anonymous_record_bad_member;
5773 if (isa<TypeDecl>(Mem))
5774 DK = diag::err_anonymous_record_with_type;
5775 else if (isa<FunctionDecl>(Mem))
5776 DK = diag::err_anonymous_record_with_function;
5777 else if (isa<VarDecl>(Mem))
5778 DK = diag::err_anonymous_record_with_static;
5781 if (getLangOpts().MicrosoftExt &&
5782 DK == diag::err_anonymous_record_with_type)
5783 Diag(Mem->getLocation(), diag::ext_anonymous_record_with_type)
5786 Diag(Mem->getLocation(), DK) <<
Record->isUnion();
5795 if (cast<CXXRecordDecl>(
Record)->hasInClassInitializer() &&
5798 cast<CXXRecordDecl>(
Record));
5802 Diag(
Record->getLocation(), diag::err_anonymous_struct_not_member)
5803 << getLangOpts().CPlusPlus;
5823 assert(TInfo &&
"couldn't build declarator info for anonymous struct/union");
5827 if (
RecordDecl *OwningClass = dyn_cast<RecordDecl>(Owner)) {
5834 ProcessDeclAttributes(S, Anon, Dc);
5837 FieldCollector->Add(cast<FieldDecl>(Anon));
5843 Diag(
Record->getLocation(), diag::err_mutable_nonmember);
5849 Record->getLocation(),
nullptr,
5851 ProcessDeclAttributes(S, Anon, Dc);
5857 ActOnUninitializedDecl(Anon);
5862 Record->setAnonymousStructOrUnion(
true);
5873 Chain.push_back(Anon);
5879 if (
VarDecl *NewVD = dyn_cast<VarDecl>(Anon)) {
5880 if (getLangOpts().
CPlusPlus && NewVD->isStaticLocal()) {
5882 Decl *ManglingContextDecl;
5883 std::tie(MCtx, ManglingContextDecl) =
5884 getCurrentMangleNumberContext(NewVD->getDeclContext());
5915 assert(
Record &&
"expected a record!");
5920 assert(TInfo &&
"couldn't build declarator info for anonymous struct");
5922 auto *ParentDecl = cast<RecordDecl>(CurContext);
5928 nullptr, RecTy, TInfo,
5934 CurContext->addDecl(Anon);
5940 Chain.push_back(Anon);
5943 if (RequireCompleteSizedType(Anon->
getLocation(), RecTy,
5944 diag::err_field_incomplete_or_sizeless) ||
5946 *
this, S, CurContext, RecordDef,
AS_none,
5949 ParentDecl->setInvalidDecl();
5958 return GetNameFromUnqualifiedId(D.
getName());
5965 NameInfo.
setLoc(Name.StartLocation);
5967 switch (Name.getKind()) {
5971 NameInfo.
setName(Name.Identifier);
5987 if (!Template || !isa<ClassTemplateDecl>(Template)) {
5988 Diag(Name.StartLocation,
5989 diag::err_deduction_guide_name_not_class_template)
5990 << (
int)getTemplateNameKindForDiagnostics(TN) << TN;
5992 NoteTemplateLocation(*Template);
6003 Name.OperatorFunctionId.Operator));
6005 Name.OperatorFunctionId.SymbolLocations[0], Name.EndLocation));
6016 QualType Ty = GetTypeFromParser(Name.ConversionFunctionId, &TInfo);
6027 QualType Ty = GetTypeFromParser(Name.ConstructorName, &TInfo);
6040 CXXRecordDecl *CurClass = dyn_cast<CXXRecordDecl>(CurContext);
6041 if (!CurClass || CurClass->
getIdentifier() != Name.TemplateId->Name)
6060 QualType Ty = GetTypeFromParser(Name.DestructorName, &TInfo);
6077 llvm_unreachable(
"Unknown name kind");
6103 if (Declaration->param_size() != Definition->param_size())
6105 for (
unsigned Idx = 0; Idx < Declaration->param_size(); ++Idx) {
6106 QualType DeclParamTy = Declaration->getParamDecl(Idx)->getType();
6107 QualType DefParamTy = Definition->getParamDecl(Idx)->getType();
6119 (DeclTyName && DeclTyName == DefTyName))
6120 Params.push_back(Idx);
6147 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case DeclSpec::TST_##Trait:
6148 #include "clang/Basic/TransformTypeTraits.def"
6163 if (!TSI)
return true;
6176 if (Result.isInvalid())
return true;
6221 << D << static_cast<int>(Status);
6231 if (LangOpts.OpenMP && OpenMP().isInOpenMPDeclareVariantScope())
6232 if (OpenMP().getOMPTraitInfoForSurroundingScope()->isExtensionActive(
6233 llvm::omp::TraitProperty::
6234 implementation_extension_bind_to_declaration))
6235 OpenMP().ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
6240 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() &&
6245 OpenMP().ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(Dcl,
6266 Diag(NameInfo.
getLoc(), diag::err_member_name_of_class) << Name;
6295 bool IsMemberSpecialization) {
6296 assert(SS.
isValid() &&
"diagnoseQualifiedDeclaration called for declaration "
6297 "without nested-name-specifier");
6299 while (isa<LinkageSpecDecl>(Cur) || isa<CapturedDecl>(Cur))
6313 Diag(Loc, LangOpts.MicrosoftExt ? diag::warn_member_extra_qualification
6314 : diag::err_member_extra_qualification)
6318 Diag(Loc, diag::warn_namespace_member_extra_qualification) << Name;
6326 if (!Cur->
Encloses(DC) && !(TemplateId || IsMemberSpecialization)) {
6328 Diag(Loc, diag::err_member_qualification)
6330 else if (isa<TranslationUnitDecl>(DC))
6331 Diag(Loc, diag::err_invalid_declarator_global_scope)
6333 else if (isa<FunctionDecl>(Cur))
6334 Diag(Loc, diag::err_invalid_declarator_in_function)
6336 else if (isa<BlockDecl>(Cur))
6337 Diag(Loc, diag::err_invalid_declarator_in_block)
6339 else if (isa<ExportDecl>(Cur)) {
6340 if (!isa<NamespaceDecl>(DC))
6341 Diag(Loc, diag::err_export_non_namespace_scope_name)
6348 Diag(Loc, diag::err_invalid_declarator_scope)
6349 << Name << cast<NamedDecl>(Cur) << cast<NamedDecl>(DC) << SS.
getRange();
6356 Diag(Loc, diag::err_member_qualification)
6382 Diag(Loc, diag::ext_template_after_declarative_nns)
6389 Diag(Loc, diag::ext_template_after_declarative_nns)
6400 if (TST->isDependentType() && TST->isTypeAlias())
6401 Diag(Loc, diag::ext_alias_template_in_declarative_nns)
6410 Diag(Loc, diag::err_computed_type_in_declarative_nns)
6414 }
while ((SpecLoc = SpecLoc.
getPrefix()));
6428 return ActOnDecompositionDeclarator(S, D, TemplateParamLists);
6434 }
else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType))
6442 UPPC_DeclarationQualifier))
6447 if (!DC || isa<EnumDecl>(DC)) {
6453 diag::err_template_qualified_declarator_no_match)
6460 if (!IsDependentContext &&
6465 if (isa<CXXRecordDecl>(DC) && !cast<CXXRecordDecl>(DC)->
hasDefinition()) {
6467 diag::err_member_def_undefined_record)
6488 if (EnteringContext && IsDependentContext &&
6489 TemplateParamLists.size() != 0) {
6500 UPPC_DeclarationType))
6504 forRedeclarationInCurContext());
6508 bool IsLinkageLookup =
false;
6509 bool CreateBuiltins =
false;
6520 else if (CurContext->isFunctionOrMethod() &&
6523 IsLinkageLookup =
true;
6525 CurContext->getEnclosingNamespaceContext()->isTranslationUnit();
6526 }
else if (CurContext->getRedeclContext()->isTranslationUnit() &&
6528 CreateBuiltins =
true;
6530 if (IsLinkageLookup) {
6531 Previous.clear(LookupRedeclarationWithLinkage);
6536 LookupName(
Previous, S, CreateBuiltins);
6572 bool AllowForCompatibility =
false;
6573 if (
Scope *DeclParent = S->getDeclParent();
6574 Scope *TemplateParamParent = S->getTemplateParamParent()) {
6575 AllowForCompatibility = DeclParent->Contains(*TemplateParamParent) &&
6576 TemplateParamParent->isDeclScope(TPD);
6579 AllowForCompatibility);
6586 if (!R->
isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo))
6602 CheckExtraCXXDefaultArguments(D);
6605 S = S->getDeclParent();
6609 bool AddToScope =
true;
6611 if (TemplateParamLists.size()) {
6616 New = ActOnTypedefDeclarator(S, D, DC, TInfo,
Previous);
6618 New = ActOnFunctionDeclarator(S, D, DC, TInfo,
Previous,
6622 New = ActOnVariableDeclarator(S, D, DC, TInfo,
Previous, TemplateParamLists,
6632 PushOnScopeChains(New, S);
6634 if (OpenMP().isInOpenMPDeclareTargetContext())
6635 OpenMP().checkDeclIsAllowedInOpenMPTarget(
nullptr, New);
6645 bool &SizeIsNegative,
6651 SizeIsNegative =
false;
6660 if (
const PointerType* PTy = dyn_cast<PointerType>(Ty)) {
6665 if (FixedType.
isNull())
return FixedType;
6667 return Qs.
apply(Context, FixedType);
6669 if (
const ParenType* PTy = dyn_cast<ParenType>(Ty)) {
6670 QualType Inner = PTy->getInnerType();
6674 if (FixedType.
isNull())
return FixedType;
6676 return Qs.
apply(Context, FixedType);
6686 SizeIsNegative, Oversized);
6699 if (Res.isSigned() && Res.isNegative()) {
6700 SizeIsNegative =
true;
6705 unsigned ActiveSizeBits =
6709 : Res.getActiveBits();
6717 return Qs.
apply(Context, FoldedArrayType);
6742 TypeLoc DstElemTL = DstATL.getElementLoc();
6761 bool &SizeIsNegative,
6765 SizeIsNegative, Oversized);
6778 unsigned FailedFoldDiagID) {
6779 bool SizeIsNegative;
6782 TInfo, Context, SizeIsNegative, Oversized);
6784 Diag(Loc, diag::ext_vla_folded_to_constant);
6791 Diag(Loc, diag::err_typecheck_negative_array_size);
6792 else if (Oversized.getBoolValue())
6793 Diag(Loc, diag::err_array_too_large) <<
toString(Oversized, 10);
6794 else if (FailedFoldDiagID)
6795 Diag(Loc, FailedFoldDiagID);
6817 return Result.empty() ? nullptr : *Result.begin();
6827 diag::err_virtual_non_function);
6831 diag::err_explicit_non_function);
6835 diag::err_noreturn_non_function);
6855 << getLangOpts().CPlusPlus17;
6863 diag::err_deduction_guide_invalid_specifier)
6872 if (!NewTD)
return nullptr;
6875 ProcessDeclAttributes(S, NewTD, D);
6877 CheckTypedefForVariablyModifiedType(S, NewTD);
6894 setFunctionHasBranchProtectedScope();
6896 if (S->getFnParent() ==
nullptr) {
6897 bool SizeIsNegative;
6911 else if (Oversized.getBoolValue())
6934 FilterLookupForScope(
Previous, DC, S,
false,
6938 Redeclaration =
true;
6939 MergeTypedefNameDecl(S, NewTD,
Previous);
6941 inferGslPointerAttribute(NewTD);
6944 if (ShadowedDecl && !Redeclaration)
6945 CheckShadow(NewTD, ShadowedDecl,
Previous);
6951 switch (II->getNotableIdentifierID()) {
6952 case tok::NotableIdentifierKind::FILE:
6955 case tok::NotableIdentifierKind::jmp_buf:
6958 case tok::NotableIdentifierKind::sigjmp_buf:
6961 case tok::NotableIdentifierKind::ucontext_t:
6964 case tok::NotableIdentifierKind::float_t:
6965 case tok::NotableIdentifierKind::double_t:
6966 NewTD->
addAttr(AvailableOnlyInDefaultEvalMethodAttr::Create(Context));
7027 if (!OuterContext->
Equals(PrevOuterContext))
7036 if (!SS.
isSet())
return;
7045 unsigned kind = -1U;
7047 if (
var->hasAttr<BlocksAttr>())
7049 else if (!
var->hasLocalStorage())
7051 }
else if (isa<ObjCIvarDecl>(
decl)) {
7053 }
else if (isa<FieldDecl>(
decl)) {
7058 Diag(
decl->getLocation(), diag::err_arc_autoreleasing_var)
7063 if (!
type->isObjCLifetimeType())
7066 lifetime =
type->getObjCARCImplicitLifetime();
7074 var->getTLSKind()) {
7075 Diag(
var->getLocation(), diag::err_arc_thread_ownership)
7085 if (
Decl->getType().hasAddressSpace())
7087 if (
Decl->getType()->isDependentType())
7098 if (getOpenCLOptions().areProgramScopeVariablesSupported(getLangOpts()) &&
7099 Var->hasGlobalStorage())
7103 if (
auto DT = dyn_cast<DecayedType>(
Type)) {
7104 auto OrigTy = DT->getOriginalType();
7105 if (!OrigTy.hasAddressSpace() && OrigTy->isArrayType()) {
7137 if (WeakRefAttr *
Attr = ND.
getAttr<WeakRefAttr>()) {
7144 if (
auto *VD = dyn_cast<VarDecl>(&ND)) {
7145 if (VD->hasInit()) {
7146 if (
const auto *
Attr = VD->getAttr<AliasAttr>()) {
7147 assert(VD->isThisDeclarationADefinition() &&
7148 !VD->isExternallyVisible() &&
"Broken AliasAttr handled late!");
7150 VD->dropAttr<AliasAttr>();
7157 if (SelectAnyAttr *
Attr = ND.
getAttr<SelectAnyAttr>()) {
7160 diag::err_attribute_selectany_non_extern_data);
7166 auto *VD = dyn_cast<VarDecl>(&ND);
7167 bool IsAnonymousNS =
false;
7170 const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(VD->getDeclContext());
7171 while (NS && !IsAnonymousNS) {
7173 NS = dyn_cast<NamespaceDecl>(NS->
getParent());
7180 bool AnonNSInMicrosoftMode = IsAnonymousNS && IsMicrosoft;
7182 (!AnonNSInMicrosoftMode &&
7191 if (
const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
7196 for (
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
7202 if (
const auto *A = ATL.
getAttrAs<LifetimeBoundAttr>()) {
7203 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
7204 if (!MD || MD->isStatic()) {
7205 S.
Diag(A->getLocation(), diag::err_lifetimebound_no_object_param)
7206 << !MD << A->getRange();
7207 }
else if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) {
7208 S.
Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor)
7209 << isa<CXXDestructorDecl>(MD) << A->getRange();
7218 bool IsSpecialization,
7219 bool IsDefinition) {
7223 bool IsTemplate =
false;
7224 if (
TemplateDecl *OldTD = dyn_cast<TemplateDecl>(OldDecl)) {
7225 OldDecl = OldTD->getTemplatedDecl();
7227 if (!IsSpecialization)
7228 IsDefinition =
false;
7230 if (
TemplateDecl *NewTD = dyn_cast<TemplateDecl>(NewDecl)) {
7231 NewDecl = NewTD->getTemplatedDecl();
7235 if (!OldDecl || !NewDecl)
7238 const DLLImportAttr *OldImportAttr = OldDecl->
getAttr<DLLImportAttr>();
7239 const DLLExportAttr *OldExportAttr = OldDecl->
getAttr<DLLExportAttr>();
7240 const DLLImportAttr *NewImportAttr = NewDecl->
getAttr<DLLImportAttr>();
7241 const DLLExportAttr *NewExportAttr = NewDecl->
getAttr<DLLExportAttr>();
7245 bool HasNewAttr = (NewImportAttr && !NewImportAttr->isInherited()) ||
7246 (NewExportAttr && !NewExportAttr->isInherited());
7252 bool AddsAttr = !(OldImportAttr || OldExportAttr) && HasNewAttr;
7254 if (AddsAttr && !IsSpecialization && !OldDecl->
isImplicit()) {
7256 bool JustWarn =
false;
7258 auto *VD = dyn_cast<VarDecl>(OldDecl);
7259 if (VD && !VD->getDescribedVarTemplate())
7261 auto *FD = dyn_cast<FunctionDecl>(OldDecl);
7270 if (!isa<FunctionDecl>(OldDecl) || !NewImportAttr)
7273 unsigned DiagID = JustWarn ? diag::warn_attribute_dll_redeclaration
7274 : diag::err_attribute_dll_redeclaration;
7277 << (NewImportAttr ? (
const Attr *)NewImportAttr : NewExportAttr);
7290 bool IsInline =
false, IsStaticDataMember =
false, IsQualifiedFriend =
false;
7292 if (
const auto *VD = dyn_cast<VarDecl>(NewDecl)) {
7295 IsStaticDataMember = VD->isStaticDataMember();
7296 IsDefinition = VD->isThisDeclarationADefinition(S.
Context) !=
7298 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(NewDecl)) {
7299 IsInline = FD->isInlined();
7300 IsQualifiedFriend = FD->getQualifier() &&
7304 if (OldImportAttr && !HasNewAttr &&
7305 (!IsInline || (IsMicrosoftABI && IsTemplate)) && !IsStaticDataMember &&
7307 if (IsMicrosoftABI && IsDefinition) {
7308 if (IsSpecialization) {
7311 diag::err_attribute_dllimport_function_specialization_definition);
7312 S.
Diag(OldImportAttr->getLocation(), diag::note_attribute);
7313 NewDecl->
dropAttr<DLLImportAttr>();
7316 diag::warn_redeclaration_without_import_attribute)
7319 NewDecl->
dropAttr<DLLImportAttr>();
7320 NewDecl->
addAttr(DLLExportAttr::CreateImplicit(
7321 S.
Context, NewImportAttr->getRange()));
7323 }
else if (IsMicrosoftABI && IsSpecialization) {
7324 assert(!IsDefinition);
7328 diag::warn_redeclaration_without_attribute_prev_attribute_ignored)
7329 << NewDecl << OldImportAttr;
7331 S.
Diag(OldImportAttr->getLocation(), diag::note_previous_attribute);
7332 OldDecl->
dropAttr<DLLImportAttr>();
7333 NewDecl->
dropAttr<DLLImportAttr>();
7335 }
else if (IsInline && OldImportAttr && !IsMicrosoftABI) {
7338 OldDecl->
dropAttr<DLLImportAttr>();
7339 NewDecl->
dropAttr<DLLImportAttr>();
7341 diag::warn_dllimport_dropped_from_inline_function)
7342 << NewDecl << OldImportAttr;
7349 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewDecl)) {
7351 !NewImportAttr && !NewExportAttr) {
7352 if (
const DLLExportAttr *ParentExportAttr =
7353 MD->getParent()->getAttr<DLLExportAttr>()) {
7354 DLLExportAttr *NewAttr = ParentExportAttr->clone(S.
Context);
7355 NewAttr->setInherited(
true);
7395 template<
typename T>
7399 if (!D->isInExternCContext() || D->template hasAttr<OverloadableAttr>())
7403 if (S.
getLangOpts().CUDA && (D->template hasAttr<CUDADeviceAttr>() ||
7404 D->template hasAttr<CUDAHostAttr>()))
7407 return D->isExternC();
7413 isa<OMPDeclareMapperDecl>(DC))
7422 if (isa<RequiresExprBodyDecl>(DC))
7424 llvm_unreachable(
"Unexpected context");
7430 isa<OMPDeclareReductionDecl>(DC) || isa<OMPDeclareMapperDecl>(DC))
7434 llvm_unreachable(
"Unexpected context");
7481 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
7482 return FD->isExternC();
7483 if (
const auto *VD = dyn_cast<VarDecl>(D))
7484 return VD->isExternC();
7486 llvm_unreachable(
"Unknown type of decl!");
7499 diag::err_opencl_type_can_only_be_used_as_function_parameter)
7513 diag::err_invalid_type_for_program_scope_var)
7542 Se.
Diag(NewVD->
getLocation(), diag::err_opencl_half_declaration) << R;
7575 Se.
Diag(NewVD->
getLocation(), diag::err_opencl_nonconst_global_sampler);
7585 template <
typename AttrTy>
7588 if (
const auto *Attribute = TND->
getAttr<AttrTy>()) {
7589 AttrTy *Clone = Attribute->clone(S.
Context);
7590 Clone->setInherited(
true);
7618 if (
const auto *ConstDecl = RD->
getAttr<ReadOnlyPlacementAttr>()) {
7620 S.
Diag(ConstDecl->getLocation(), diag::note_enforce_read_only_placement);
7633 bool IsPlaceholderVariable =
false;
7639 if (!Decomp.bindings().empty()) {
7640 II = Decomp.bindings()[0].Name;
7654 IsPlaceholderVariable =
true;
7659 if (SameDC && isDeclInScope(PrevDecl, CurContext, S,
false))
7672 bool IsLocalExternDecl = SC ==
SC_Extern &&
7673 adjustContextForLocalExternDecl(DC);
7684 !D.
getAsmLabel() && !getSourceManager().isInSystemMacro(
7690 getLangOpts().
CPlusPlus17 ? diag::ext_register_storage_class
7691 : diag::warn_deprecated_register)
7697 if (!DC->
isRecord() && S->getFnParent() ==
nullptr) {
7713 bool IsMemberSpecialization =
false;
7714 bool IsVariableTemplateSpecialization =
false;
7716 bool IsVariableTemplate =
false;
7725 ParsingInitForAutoVars.insert(NewVD);
7733 NTCUC_AutoVar, NTCUK_Destruct);
7735 bool Invalid =
false;
7737 if (DC->
isRecord() && !CurContext->isRecord()) {
7744 diag::err_static_out_of_line)
7756 diag::err_storage_class_for_static_member)
7760 llvm_unreachable(
"C storage class in c++!");
7764 if (SC ==
SC_Static && CurContext->isRecord()) {
7765 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) {
7771 if (Ctxt->isFunctionOrMethod()) {
7772 FunctionOrMethod = Ctxt;
7775 const CXXRecordDecl *ParentDecl = dyn_cast<CXXRecordDecl>(Ctxt);
7777 AnonStruct = ParentDecl;
7781 if (FunctionOrMethod) {
7785 diag::err_static_data_member_not_allowed_in_local_class)
7786 << Name << RD->getDeclName()
7787 << llvm::to_underlying(RD->getTagKind());
7788 }
else if (AnonStruct) {
7793 diag::err_static_data_member_not_allowed_in_anon_struct)
7794 << Name << llvm::to_underlying(AnonStruct->
getTagKind());
7796 }
else if (RD->isUnion()) {
7801 ? diag::warn_cxx98_compat_static_data_member_in_union
7802 : diag::ext_static_data_member_in_union) << Name;
7809 bool InvalidScope =
false;
7810 TemplateParams = MatchTemplateParametersToScopeSpecifier(
7817 false, IsMemberSpecialization, InvalidScope);
7818 Invalid |= InvalidScope;
7820 if (TemplateParams) {
7821 if (!TemplateParams->
size() &&
7826 diag::err_template_variable_noparams)
7830 TemplateParams =
nullptr;
7833 if (CheckTemplateDeclScope(S, TemplateParams))
7838 IsVariableTemplateSpecialization =
true;
7842 IsVariableTemplate =
true;
7847 ? diag::warn_cxx11_compat_variable_template
7848 : diag::ext_variable_template);
7853 if (!TemplateParamLists.empty() && IsMemberSpecialization &&
7854 CheckTemplateDeclScope(S, TemplateParamLists.back()))
7858 "should have a 'template<>' for this decl");
7861 if (IsVariableTemplateSpecialization) {
7863 TemplateParamLists.size() > 0
7864 ? TemplateParamLists[0]->getTemplateLoc()
7866 DeclResult Res = ActOnVarTemplateSpecialization(
7867 S, D, TInfo,
Previous, TemplateKWLoc, TemplateParams, SC,
7871 NewVD = cast<VarDecl>(Res.
get());
7882 if (IsVariableTemplate) {
7885 TemplateParams, NewVD);
7892 ParsingInitForAutoVars.insert(NewVD);
7906 bool IsExplicitSpecialization =
7908 unsigned VDTemplateParamLists =
7909 (TemplateParams && !IsExplicitSpecialization) ? 1 : 0;
7910 if (TemplateParamLists.size() > VDTemplateParamLists)
7912 Context, TemplateParamLists.drop_back(VDTemplateParamLists));
7916 if (!getLangOpts().CPlusPlus) {
7919 }
else if (CurContext->isFunctionOrMethod()) {
7922 diag::err_inline_declaration_block_scope) << Name
7926 getLangOpts().
CPlusPlus17 ? diag::warn_cxx14_compat_inline_variable
7927 : diag::ext_inline_variable);
7938 if (IsLocalExternDecl) {
7941 B->setLocalExternDecl();
7946 bool EmitTLSUnsupportedError =
false;
7959 diag::err_thread_non_global)
7962 if (getLangOpts().
CUDA || getLangOpts().OpenMPIsTargetDevice ||
7963 getLangOpts().SYCLIsDevice) {
7967 EmitTLSUnsupportedError =
true;
7974 diag::err_thread_unsupported);
7979 if (getLangOpts().SYCLIsDevice) {
7981 if (
const ArrayType *AT = getASTContext().getAsArrayType(NewVD->
getType()))
7982 if (SYCL().isTypeDecoratedWithDeclAttribute<SYCLDeviceGlobalAttr>(
7983 AT->getElementType()))
7988 if (SYCL().isTypeDecoratedWithDeclAttribute<SYCLDeviceGlobalAttr>(
7993 if (isa<FunctionDecl>(DC)) {
7995 diag::err_sycl_device_global_incorrect_scope);
8002 diag::err_sycl_device_global_incorrect_scope);
8010 !SYCL().isTypeDecoratedWithDeclAttribute<SYCLGlobalVariableAllowedAttr>(
8022 diag::err_constexpr_wrong_decl_kind)
8032 (getLangOpts().CPlusPlus17 ||
8040 diag::err_constinit_local_variable);
8044 ConstInitAttr::Keyword_constinit));
8057 if (SC ==
SC_Static && S->getFnParent() !=
nullptr &&
8062 diag::warn_static_local_in_extern_inline);
8063 MaybeSuggestAddingStaticToDecl(CurFD);
8068 if (IsVariableTemplateSpecialization)
8073 else if (IsMemberSpecialization)
8088 B->setModulePrivate();
8092 if (getLangOpts().
OpenCL) {
8093 deduceOpenCLAddressSpace(NewVD);
8098 diag::err_opencl_unknown_type_specifier)
8099 << getLangOpts().getOpenCLVersionString()
8108 if (
const auto *ATy = dyn_cast<ArrayType>(NewVD->
getType())) {
8109 if (ATy && ATy->getElementType().isWebAssemblyReferenceType() &&
8118 ProcessDeclAttributes(S, NewVD, D);
8126 copyAttrFromTypedefToDecl<AllocSizeAttr>(*
this, NewVD, TT);
8128 if (getLangOpts().
CUDA || getLangOpts().OpenMPIsTargetDevice ||
8129 getLangOpts().SYCLIsDevice) {
8130 if (EmitTLSUnsupportedError &&
8132 (getLangOpts().OpenMPIsTargetDevice &&
8133 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(NewVD))))
8135 diag::err_thread_unsupported);
8137 if (EmitTLSUnsupportedError &&
8138 (LangOpts.SYCLIsDevice ||
8139 (LangOpts.OpenMP && LangOpts.OpenMPIsTargetDevice)))
8143 if (SC ==
SC_None && S->getFnParent() !=
nullptr &&
8144 (NewVD->
hasAttr<CUDASharedAttr>() ||
8145 NewVD->
hasAttr<CUDAConstantAttr>())) {
8153 assert(!NewVD->
hasAttr<DLLImportAttr>() ||
8154 NewVD->
getAttr<DLLImportAttr>()->isInherited() ||
8159 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewVD))
8167 if (S->getFnParent() !=
nullptr) {
8171 Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) <<
Label;
8177 if (getLangOpts().SYCLIsDevice)
8178 SYCL().DiagIfDeviceCode(E->getExprLoc(),
8179 diag::err_asm_unknown_register_name)
8182 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) <<
Label;
8194 bool HasSizeMismatch;
8196 if (!TI.isValidGCCRegisterName(
Label))
8197 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) <<
Label;
8198 else if (!TI.validateGlobalRegisterVariable(
Label,
8201 Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) <<
Label;
8202 else if (HasSizeMismatch)
8203 Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) <<
Label;
8215 }
else if (!ExtnameUndeclaredIdentifiers.empty()) {
8216 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
8218 if (I != ExtnameUndeclaredIdentifiers.end()) {
8221 ExtnameUndeclaredIdentifiers.erase(I);
8230 ? getShadowedDeclaration(NewVD,
Previous)
8238 IsMemberSpecialization ||
8239 IsVariableTemplateSpecialization);
8247 isDeclInScope(
Previous.getFoundDecl(), OriginalDC, S,
false));
8253 if (IsMemberSpecialization && !IsVariableTemplateSpecialization &&
8260 isa<FieldDecl>(
Previous.getFoundDecl()) &&
8270 !IsVariableTemplateSpecialization) {
8278 if (!IsPlaceholderVariable)
8297 if (CheckTemplateParameterList(
8303 ? TPC_ClassTemplateMember
8309 if (PrevVarTemplate &&
8317 CheckShadow(NewVD, ShadowedDecl,
Previous);
8319 ProcessPragmaWeak(S, NewVD);
8325 RegisterLocallyScopedExternCDecl(NewVD, S);
8329 Decl *ManglingContextDecl;
8330 std::tie(MCtx, ManglingContextDecl) =
8341 if (Name.getAsIdentifierInfo() && Name.getAsIdentifierInfo()->isStr(
"main") &&
8365 ActOnDocumentableDecl(NewTemplate);
8370 CompleteMemberSpecialization(NewVD,
Previous);
8372 SYCL().addSyclVarDecl(NewVD);
8392 if (isa<TypeAliasDecl>(ShadowedDecl))
8394 else if (isa<TypedefDecl>(ShadowedDecl))
8396 else if (isa<BindingDecl>(ShadowedDecl))
8398 else if (isa<RecordDecl>(OldDC))
8437 return isa<VarDecl, FieldDecl, BindingDecl>(ShadowedDecl) ? ShadowedDecl
8453 return isa<TypedefNameDecl>(ShadowedDecl) ? ShadowedDecl :
nullptr;
8464 return isa<VarDecl, FieldDecl, BindingDecl>(ShadowedDecl) ? ShadowedDecl
8481 if (
FieldDecl *FD = dyn_cast<FieldDecl>(ShadowedDecl)) {
8489 if (isa<CXXConstructorDecl>(NewDC))
8490 if (
const auto PVD = dyn_cast<ParmVarDecl>(D)) {
8493 ShadowingDecls.insert({PVD->getCanonicalDecl(), FD});
8498 if (
VarDecl *shadowedVar = dyn_cast<VarDecl>(ShadowedDecl))
8499 if (shadowedVar->isExternC()) {
8502 for (
auto *I : shadowedVar->redecls())
8503 if (I->isFileVarDecl()) {
8511 unsigned WarningDiag = diag::warn_decl_shadow;
8513 if (isa<VarDecl>(D) && NewDC && isa<CXXMethodDecl>(NewDC)) {
8514 if (
const auto *RD = dyn_cast<CXXRecordDecl>(NewDC->
getParent())) {
8516 if (
const auto *VD = dyn_cast<VarDecl>(ShadowedDecl)) {
8517 const auto *LSI = cast<LambdaScopeInfo>(getCurFunction());
8518 if (RD->getLambdaCaptureDefault() ==
LCD_None) {
8524 WarningDiag = diag::warn_decl_shadow_uncaptured_local;
8529 cast<LambdaScopeInfo>(getCurFunction())
8530 ->ShadowingDecls.push_back({D, VD});
8534 if (isa<FieldDecl>(ShadowedDecl)) {
8540 cast<LambdaScopeInfo>(getCurFunction())
8541 ->ShadowingDecls.push_back({D, ShadowedDecl});
8545 if (
const auto *VD = dyn_cast<VarDecl>(ShadowedDecl);
8546 VD && VD->hasLocalStorage()) {
8550 ParentDC && !ParentDC->
Equals(OldDC);
8554 if (!isa<BlockDecl>(ParentDC) && !isa<CapturedDecl>(ParentDC) &&
8588 Diag(CaptureLoc, diag::note_var_explicitly_captured_here)
8597 const NamedDecl *ShadowedDecl = Shadow.ShadowedDecl;
8600 if (
const auto *VD = dyn_cast<VarDecl>(ShadowedDecl)) {
8602 Diag(Shadow.VD->getLocation(),
8603 CaptureLoc.
isInvalid() ? diag::warn_decl_shadow_uncaptured_local
8604 : diag::warn_decl_shadow)
8605 << Shadow.VD->getDeclName()
8608 Diag(CaptureLoc, diag::note_var_explicitly_captured_here)
8609 << Shadow.VD->getDeclName() << 0;
8611 }
else if (isa<FieldDecl>(ShadowedDecl)) {
8612 Diag(Shadow.VD->getLocation(),
8614 : diag::warn_decl_shadow_uncaptured_local)
8615 << Shadow.VD->getDeclName()
8624 if (Diags.isIgnored(diag::warn_decl_shadow, D->
getLocation()))
8631 if (
NamedDecl *ShadowedDecl = getShadowedDeclaration(D, R))
8632 CheckShadow(D, ShadowedDecl, R);
8639 if (!getLangOpts().
CPlusPlus || ShadowingDecls.empty())
8642 auto *DRE = dyn_cast<DeclRefExpr>(E);
8645 const NamedDecl *D = cast<NamedDecl>(DRE->getDecl()->getCanonicalDecl());
8646 auto I = ShadowingDecls.find(D);
8647 if (I == ShadowingDecls.end())
8649 const NamedDecl *ShadowedDecl = I->second;
8651 Diag(Loc, diag::warn_modifying_shadowing_decl) << D << OldDC;
8656 ShadowingDecls.erase(I);
8661 template<
typename T>
8664 assert(S.
getLangOpts().CPlusPlus &&
"only C++ has extern \"C\"");
8685 if (!isa<VarDecl>(ND))
8695 if (isa<VarDecl>(*I)) {
8705 if (isa<VarDecl>(*I)) {
8723 assert(Prev &&
"should have found a previous declaration to diagnose");
8725 Prev = FD->getFirstDecl();
8727 Prev = cast<VarDecl>(Prev)->getFirstDecl();
8729 S.
Diag(ND->getLocation(), diag::err_extern_c_global_conflict)
8744 template<
typename T>
8751 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
8763 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit())
8783 SemaRef.
Diag(VarLoc, diag::err_c23_constexpr_invalid_type) <<
T;
8793 SemaRef.
Diag(VarLoc, diag::err_c23_constexpr_invalid_type) <<
T;
8799 if (llvm::any_of(RD->
fields(), [&SemaRef, VarLoc](
const FieldDecl *F) {
8800 return CheckC23ConstexprVarType(SemaRef, VarLoc, F->getType());
8820 CheckAlignasUnderalignment(NewVD);
8842 if (getLangOpts().OpenCLVersion == 120 &&
8843 !getOpenCLOptions().isAvailableOption(
"cl_clang_storage_class_specifiers",
8851 if (getLangOpts().
OpenCL) {
8856 if (NewVD->
hasAttr<BlocksAttr>()) {
8864 if (!
T.isConstQualified()) {
8865 Diag(NewVD->
getLocation(), diag::err_opencl_invalid_block_declaration)
8871 Diag(NewVD->
getLocation(), diag::err_opencl_extern_block_declaration);
8883 getOpenCLOptions().areProgramScopeVariablesSupported(
8886 if (getOpenCLOptions().areProgramScopeVariablesSupported(getLangOpts()))
8887 Diag(NewVD->
getLocation(), diag::err_opencl_global_invalid_addr_space)
8888 <<
Scope <<
"global or constant";
8890 Diag(NewVD->
getLocation(), diag::err_opencl_global_invalid_addr_space)
8891 <<
Scope <<
"constant";
8907 if (FD && !FD->
hasAttr<OpenCLKernelAttr>()) {
8919 if (FD && FD->
hasAttr<OpenCLKernelAttr>()) {
8920 if (!getCurScope()->isFunctionScope()) {
8944 && !NewVD->
hasAttr<BlocksAttr>()) {
8948 assert(!getLangOpts().ObjCAutoRefCount);
8956 if (getCurScope()->getParent()) {
8966 const auto *ATy = dyn_cast<ConstantArrayType>(
T.getTypePtr());
8967 if (!ATy || ATy->getZExtSize() != 0) {
8969 diag::err_typecheck_wasm_table_must_have_zero_length);
8976 if (isVM || NewVD->
hasAttr<CleanupAttr>() ||
8978 setFunctionHasBranchProtectedScope();
8982 bool SizeIsNegative;
8988 FixedT = FixedTInfo->
getType();
8989 else if (FixedTInfo) {
9046 !
T.isWebAssemblyReferenceType()) {
9052 if (isVM && NewVD->
hasAttr<BlocksAttr>()) {
9066 diag::err_constexpr_var_non_literal)) {
9081 const FunctionDecl *FD = cast<FunctionDecl>(CurContext);
9082 llvm::StringMap<bool> CallerFeatureMap;
9085 "sve", CallerFeatureMap)) {
9093 const FunctionDecl *FD = cast<FunctionDecl>(CurContext);
9094 llvm::StringMap<bool> CallerFeatureMap;
9096 checkRVVTypeSupport(
T, NewVD->
getLocation(), cast<Decl>(CurContext),
9114 CheckVariableDeclarationType(NewVD);
9154 dyn_cast<CXXMethodDecl>(BaseND->getCanonicalDecl());
9156 IsOverride(MD, BaseMD,
false,
9159 if (!CheckExplicitObjectOverride(MD, BaseMD))
9161 if (Overridden.insert(BaseMD).second) {
9163 CheckOverridingFunctionReturnType(MD, BaseMD);
9164 CheckOverridingFunctionAttributes(MD, BaseMD);
9165 CheckOverridingFunctionExceptionSpec(MD, BaseMD);
9166 CheckIfOverriddenFunctionIsMarkedFinal(MD, BaseMD);
9178 return !Overridden.empty();
9184 struct ActOnFDArgs {
9200 : Context(Context), OriginalFD(TypoFD),
9203 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
9209 CDeclEnd = candidate.
end();
9210 CDecl != CDeclEnd; ++CDecl) {
9217 if (
Parent &&
Parent->getCanonicalDecl() == ExpectedParent)
9219 }
else if (!ExpectedParent) {
9228 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
9229 return std::make_unique<DifferentNameValidatorCCC>(*
this);
9241 TypoCorrectedFunctionDefinitions.insert(F);
9255 ActOnFDArgs &ExtraArgs,
bool IsLocalFriend,
Scope *S) {
9261 bool IsDefinition = ExtraArgs.D.isFunctionDefinition();
9263 IsLocalFriend ? diag::err_no_matching_local_friend :
9265 diag::err_member_decl_does_not_match;
9277 "Cannot have an ambiguity in previous-declaration lookup");
9279 DifferentNameValidatorCCC CCC(SemaRef.
Context, NewFD,
9281 if (!Prev.
empty()) {
9290 MismatchedParams.empty() ? 0 : MismatchedParams.front() + 1;
9291 NearMatches.push_back(std::make_pair(FD, ParamNum));
9298 IsLocalFriend ?
nullptr : NewDC))) {
9301 ExtraArgs.D.getIdentifierLoc());
9305 CDeclEnd = Correction.
end();
9306 CDecl != CDeclEnd; ++CDecl) {
9313 bool wasRedeclaration = ExtraArgs.D.isRedeclaration();
9326 ExtraArgs.S, ExtraArgs.D,
9329 ExtraArgs.AddToScope);
9340 if ((*I)->getCanonicalDecl() == Canonical)
9347 SemaRef.
PDiag(IsLocalFriend
9348 ? diag::err_no_matching_local_friend_suggest
9349 : diag::err_member_decl_does_not_match_suggest)
9350 << Name << NewDC << IsDefinition);
9355 ExtraArgs.D.SetIdentifier(Name.getAsIdentifierInfo(),
9356 ExtraArgs.D.getIdentifierLoc());
9357 ExtraArgs.D.setRedeclaration(wasRedeclaration);
9363 << Name << NewDC << IsDefinition << NewFD->
getLocation();
9365 bool NewFDisConst =
false;
9367 NewFDisConst = NewMD->isConst();
9370 NearMatch = NearMatches.begin(), NearMatchEnd = NearMatches.end();
9371 NearMatch != NearMatchEnd; ++NearMatch) {
9374 bool FDisConst = MD && MD->
isConst();
9375 bool IsMember = MD || !IsLocalFriend;
9378 if (
unsigned Idx = NearMatch->second) {
9382 SemaRef.
Diag(Loc, IsMember ? diag::note_member_def_close_param_match
9383 : diag::note_local_decl_close_param_match)
9386 }
else if (FDisConst != NewFDisConst) {
9387 SemaRef.
Diag(FD->
getLocation(), diag::note_member_def_close_const_match)
9391 .getConstQualifierLoc())
9394 .getLocWithOffset(1),
9398 IsMember ? diag::note_member_def_close_match
9399 : diag::note_local_decl_close_match);
9406 default: llvm_unreachable(
"Unknown storage class!");
9411 diag::err_typecheck_sclass_func);
9428 diag::err_static_block_func);
9444 bool &IsVirtualOkay) {
9458 diag::err_c23_constexpr_not_variable);
9461 diag::err_constexpr_wrong_decl_kind)
9462 <<
static_cast<int>(ConstexprKind);
9482 ->isFunctionProtoType()) ||
9486 "Strict prototypes are required");
9507 "Constructors can only be declared in a member context");
9513 isInline,
false, ConstexprKind,
9524 false, ConstexprKind,
9525 TrailingRequiresClause);
9528 if (
Record->isBeingDefined())
9537 IsVirtualOkay =
true;
9549 true, ConstexprKind, TrailingRequiresClause);
9555 diag::err_conv_function_not_member);
9563 IsVirtualOkay =
true;
9568 TrailingRequiresClause);
9571 if (TrailingRequiresClause)
9573 diag::err_trailing_requires_clause_on_deduction_guide)
9585 if (Name.getAsIdentifierInfo() &&
9586 Name.getAsIdentifierInfo() == cast<CXXRecordDecl>(DC)->getIdentifier()){
9598 IsVirtualOkay = !
Ret->isStatic();
9612 true , ConstexprKind, TrailingRequiresClause);
9629 StringRef SizeTypeNames[] = {
"size_t",
"intptr_t",
"uintptr_t",
"ptrdiff_t"};
9637 if (Names.end() != Match)
9642 }
while (DesugaredTy != Ty);
9681 "__cl_clang_non_portable_kernel_param_types", S.
getLangOpts())) {
9683 bool IsStandardLayoutType =
true;
9689 if (!CXXRec->hasDefinition())
9691 if (!CXXRec || !CXXRec->hasDefinition() || !CXXRec->isStandardLayout())
9692 IsStandardLayoutType =
false;
9695 !IsStandardLayoutType)
9743 "__cl_clang_non_portable_kernel_param_types", S.
getLangOpts()) &&
9757 llvm::SmallPtrSetImpl<const Type *> &ValidTypes) {
9804 S.
Diag(Loc, diag::note_entity_declared_at) << PT;
9827 HistoryStack.push_back(
nullptr);
9836 VisitStack.push_back(RecTy->
getDecl());
9837 assert(VisitStack.back() &&
"First decl null?");
9840 const Decl *Next = VisitStack.pop_back_val();
9842 assert(!HistoryStack.empty());
9844 if (
const FieldDecl *Hist = HistoryStack.pop_back_val())
9845 ValidTypes.insert(Hist->getType().getTypePtr());
9853 if (
const FieldDecl *Field = dyn_cast<FieldDecl>(Next)) {
9854 HistoryStack.push_back(Field);
9856 QualType FieldTy = Field->getType();
9860 "Unexpected type.");
9865 RD = cast<RecordDecl>(Next);
9869 VisitStack.push_back(
nullptr);
9871 for (
const auto *FD : RD->
fields()) {
9882 VisitStack.push_back(FD);
9894 diag::err_record_with_pointers_kernel_param)
9901 S.
Diag(OrigRecDecl->getLocation(), diag::note_within_field_of_type)
9902 << OrigRecDecl->getDeclName();
9907 I = HistoryStack.begin() + 1,
9908 E = HistoryStack.end();
9921 }
while (!VisitStack.empty());
9937 while (S->isClassScope() ||
9938 (LangOpts.CPlusPlus &&
9939 S->isFunctionPrototypeScope()) ||
9941 (S->getEntity() && S->getEntity()->isTransparentContext()))
9948 unsigned BuiltinID) {
9949 switch (BuiltinID) {
9950 case Builtin::BI__GetExceptionInfo:
9954 case Builtin::BIaddressof:
9955 case Builtin::BI__addressof:
9956 case Builtin::BIforward:
9957 case Builtin::BIforward_like:
9958 case Builtin::BImove:
9959 case Builtin::BImove_if_noexcept:
9960 case Builtin::BIas_const: {
9985 llvm::append_range(TemplateParamLists, TemplateParamListsRef);
9987 if (!TemplateParamLists.empty() && !TemplateParamLists.back()->empty() &&
9988 Invented->getDepth() == TemplateParamLists.back()->getDepth())
9989 TemplateParamLists.back() = Invented;
9991 TemplateParamLists.push_back(Invented);
10001 diag::err_invalid_thread)
10005 adjustMemberFunctionCC(
10009 bool isFriend =
false;
10011 bool isMemberSpecialization =
false;
10012 bool isFunctionTemplateSpecialization =
false;
10014 bool HasExplicitTemplateArgs =
false;
10017 bool isVirtualOkay =
false;
10020 bool IsLocalExternDecl = adjustContextForLocalExternDecl(DC);
10024 if (!NewFD)
return nullptr;
10026 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer())
10034 if (IsLocalExternDecl)
10043 bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlusModules ||
10066 if (
Parent->isInterface() && cast<CXXMethodDecl>(NewFD)->isUserProvided())
10071 if (isVirtual &&
Parent->isUnion()) {
10076 Parent->hasAttr<SYCLSpecialClassAttr>() &&
10079 if (
auto *Def =
Parent->getDefinition())
10080 Def->setInitMethod(
true);
10085 isMemberSpecialization =
false;
10086 isFunctionTemplateSpecialization =
false;
10092 bool Invalid =
false;
10098 MatchTemplateParametersToScopeSpecifier(
10101 isMemberSpecialization, Invalid);
10102 if (TemplateParams) {
10104 if (CheckTemplateDeclScope(S, TemplateParams))
10107 if (TemplateParams->
size() > 0) {
10115 }
else if (TemplateId) {
10126 if (RebuildTemplateParamsInCurrentInstantiation(TemplateParams))
10132 Name, TemplateParams,
10138 if (TemplateParamLists.size() > 1) {
10145 isFunctionTemplateSpecialization =
true;
10147 if (TemplateParamLists.size() > 0)
10163 InsertLoc = getLocForEndOfToken(InsertLoc);
10167 << Name << RemoveRange
10173 HasExplicitTemplateArgs =
true;
10180 if (!TemplateParamLists.empty() && isMemberSpecialization &&
10181 CheckTemplateDeclScope(S, TemplateParamLists.back()))
10186 if (TemplateParamLists.size() > 0)
10191 if (isFriend && TemplateId)
10192 isFunctionTemplateSpecialization =
true;
10198 if (isFunctionTemplateSpecialization && TemplateId) {
10199 HasExplicitTemplateArgs =
true;
10205 translateTemplateArguments(TemplateArgsPtr, TemplateArgs);
10211 if (DiagnoseUnexpandedParameterPack(
10212 ArgLoc, isFriend ? UPPC_FriendDeclaration
10213 : UPPC_ExplicitSpecialization))
10220 if (FunctionTemplate)
10230 if (!isVirtualOkay) {
10232 diag::err_virtual_non_function);
10233 }
else if (!CurContext->isRecord()) {
10236 diag::err_virtual_out_of_class)
10242 diag::err_virtual_member_function_template)
10258 if (CurContext->isFunctionOrMethod()) {
10261 diag::err_inline_declaration_block_scope) << Name
10271 !isa<CXXDeductionGuideDecl>(NewFD)) {
10272 if (!CurContext->isRecord()) {
10275 diag::err_explicit_out_of_class)
10277 }
else if (!isa<CXXConstructorDecl>(NewFD) &&
10278 !isa<CXXConversionDecl>(NewFD)) {
10282 diag::err_explicit_non_ctor_or_conv_function)
10296 if (isa<CXXDestructorDecl>(NewFD) &&
10300 <<
static_cast<int>(ConstexprKind);
10314 diag::err_invalid_consteval_decl_kind)
10322 if (isFunctionTemplateSpecialization) {
10325 Diag(ModulePrivateLoc, diag::err_module_private_specialization)
10330 if (FunctionTemplate)
10336 if (FunctionTemplate) {
10360 if (isa<CXXMethodDecl>(NewFD) && DC == CurContext &&
10371 if (SC ==
SC_Static && isa<CXXMethodDecl>(NewFD) &&
10372 !CurContext->isRecord()) {
10386 cast<CXXRecordDecl>(DC)->getDescribedClassTemplate()) ||
10388 ? diag::ext_static_out_of_line : diag::err_static_out_of_line)
10396 if ((Name.getCXXOverloadedOperator() == OO_Delete ||
10397 Name.getCXXOverloadedOperator() == OO_Array_Delete) &&
10412 PendingInlineFuncDecls.insert(NewFD);
10419 isMemberSpecialization ||
10420 isFunctionTemplateSpecialization);
10429 }
else if (!ExtnameUndeclaredIdentifiers.empty()) {
10430 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
10432 if (I != ExtnameUndeclaredIdentifiers.end()) {
10435 ExtnameUndeclaredIdentifiers.erase(I);
10455 for (
unsigned i = 0, e = FTI.
NumParams; i != e; ++i) {
10459 Params.push_back(Param);
10474 auto *TD = dyn_cast<TagDecl>(NonParmDecl);
10479 if (
auto *ECD = dyn_cast<EnumConstantDecl>(NonParmDecl))
10480 TD = cast<EnumDecl>(ECD->getDeclContext());
10484 DeclContext *TagDC = TD->getLexicalDeclContext();
10488 TD->setDeclContext(NewFD);
10496 if (TagDC != PrototypeTagContext)
10497 TD->setLexicalDeclContext(TagDC);
10511 for (
const auto &AI : FT->param_types()) {
10515 Params.push_back(Param);
10519 "Should not need args for typedef of non-prototype fn");
10523 NewFD->setParams(Params);
10539 !NewFD->
hasAttr<SectionAttr>())
10540 NewFD->
addAttr(PragmaClangTextSectionAttr::CreateImplicit(
10541 Context, PragmaClangTextSection.SectionName,
10542 PragmaClangTextSection.PragmaLocation));
10546 !NewFD->
hasAttr<SectionAttr>()) {
10547 NewFD->
addAttr(SectionAttr::CreateImplicit(
10548 Context, CodeSegStack.CurrentValue->getString(),
10549 CodeSegStack.CurrentPragmaLocation, SectionAttr::Declspec_allocate));
10550 if (UnifySection(CodeSegStack.CurrentValue->getString(),
10560 !NewFD->
hasAttr<StrictGuardStackCheckAttr>())
10561 NewFD->
addAttr(StrictGuardStackCheckAttr::CreateImplicit(
10562 Context, PragmaClangTextSection.PragmaLocation));
10566 if (!NewFD->
hasAttr<CodeSegAttr>()) {
10567 if (
Attr *SAttr = getImplicitCodeSegOrSectionAttrForFunction(NewFD,
10574 ProcessDeclAttributes(S, NewFD, D);
10575 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
10576 if (NewTVA && !NewTVA->isDefaultVersion() &&
10579 AddToScope =
false;
10583 if (getLangOpts().OpenCL || getLangOpts().HLSL) {
10591 Diag(NewFD->
getLocation(), diag::err_return_value_with_address_space);
10602 CheckMSVCRTEntryPoint(NewFD);
10606 isMemberSpecialization,
10613 "previous declaration set still overloaded");
10625 CC ==
CC_X86StdCall ? diag::warn_cconv_knr : diag::err_cconv_knr;
10635 NTCUC_FunctionReturn, NTCUK_Destruct|NTCUK_Copy);
10648 diag::ext_operator_new_delete_declared_inline)
10674 if (!FunctionTemplate) {
10675 if (isFunctionTemplateSpecialization || isMemberSpecialization) {
10687 Diag(TRC->getBeginLoc(), diag::err_non_temp_spec_requires_clause)
10695 diag::err_non_temp_friend_decl_with_requires_clause_must_be_def);
10699 Diag(TRC->getBeginLoc(),
10700 diag::err_constrained_non_templated_function);
10711 if (getLangOpts().
CUDA && !isFunctionTemplateSpecialization)
10717 if (isFunctionTemplateSpecialization) {
10718 bool isDependentSpecialization =
false;
10723 isDependentSpecialization =
10725 (HasExplicitTemplateArgs &&
10729 assert((!isDependentSpecialization ||
10730 (HasExplicitTemplateArgs == isDependentSpecialization)) &&
10731 "dependent friend function specialization without template "
10737 isDependentSpecialization =
10738 CurContext->isRecord() && CurContext->isDependentContext();
10742 HasExplicitTemplateArgs ? &TemplateArgs :
nullptr;
10743 if (isDependentSpecialization) {
10749 if (CheckDependentFunctionTemplateSpecialization(
10750 NewFD, ExplicitTemplateArgs,
Previous))
10753 if (CheckFunctionTemplateSpecialization(NewFD, ExplicitTemplateArgs,
10767 diag::err_explicit_specialization_inconsistent_storage_class)
10774 diag::ext_explicit_specialization_storage_class)
10778 }
else if (isMemberSpecialization && isa<CXXMethodDecl>(NewFD)) {
10779 if (CheckMemberSpecialization(NewFD,
Previous))
10788 CheckMSVCRTEntryPoint(NewFD);
10792 isMemberSpecialization,
10801 "previous declaration set still overloaded");
10803 NamedDecl *PrincipalDecl = (FunctionTemplate
10804 ? cast<NamedDecl>(FunctionTemplate)
10813 if (FunctionTemplate) FunctionTemplate->
setAccess(Access);
10822 if (FunctionTemplate) {
10830 ? TPC_FriendFunctionTemplateDefinition
10831 : TPC_FriendFunctionTemplate)
10835 ? TPC_ClassTemplateMember
10836 : TPC_FunctionTemplate);
10842 struct ActOnFDArgs ExtraArgs = { S, D, TemplateParamLists,
10865 (!
Previous.empty() && CurContext->isDependentContext()))) {
10888 *
this,
Previous, NewFD, ExtraArgs,
false,
nullptr)) {
10889 AddToScope = ExtraArgs.AddToScope;
10896 }
else if (isFriend && cast<CXXRecordDecl>(CurContext)->isLocalClass()) {
10898 *
this,
Previous, NewFD, ExtraArgs,
true, S)) {
10899 AddToScope = ExtraArgs.AddToScope;
10904 isa<CXXMethodDecl>(NewFD) && NewFD->
isOutOfLine() &&
10905 !isFriend && !isFunctionTemplateSpecialization &&
10906 !isMemberSpecialization) {
10921 if (!NewFD->
isInvalidDecl() && S->getDepth() == 0 && Name.isIdentifier())
10922 HLSL().ActOnTopLevelFunction(NewFD);
10924 if (NewFD->
hasAttr<HLSLShaderAttr>())
10925 HLSL().CheckEntryPoint(NewFD);
10932 if (
unsigned BuiltinID = II->getBuiltinID()) {
10934 if (!InStdNamespace &&
10940 NewFD->
addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
10943 LookupNecessaryTypesForBuiltin(S, BuiltinID);
10949 NewFD->
addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
10954 NewFD->
addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
10960 ProcessPragmaWeak(S, NewFD);
10963 AddKnownFunctionAttributes(NewFD);
10965 if (NewFD->
hasAttr<OverloadableAttr>() &&
10968 diag::err_attribute_overloadable_no_prototype)
10970 NewFD->
dropAttr<OverloadableAttr>();
10976 AddPushedVisibilityAttribute(NewFD);
10980 AddCFAuditedAttribute(NewFD);
10985 AddRangeBasedOptnone(NewFD);
10986 AddImplicitMSFunctionNoBuiltinAttr(NewFD);
10987 AddSectionMSAllocText(NewFD);
10988 ModifyFnAttributesMSPragmaOptimize(NewFD);
10995 RegisterLocallyScopedExternCDecl(NewFD, S);
11003 isMemberSpecialization ||
11004 isFunctionTemplateSpecialization,
11008 if (getLangOpts().
CUDA) {
11010 if (II && II->
isStr(
CUDA().getConfigureFuncName()) &&
11015 <<
CUDA().getConfigureFuncName();
11022 if (!getLangOpts().CUDAAllowVariadicFunctions && NewFD->
isVariadic() &&
11023 (NewFD->
hasAttr<CUDADeviceAttr>() ||
11024 NewFD->
hasAttr<CUDAGlobalAttr>()) &&
11031 MarkUnusedFileScopedDecl(NewFD);
11035 if (getLangOpts().
OpenCL && NewFD->
hasAttr<OpenCLKernelAttr>()) {
11055 if (getLangOpts().OpenCLCPlusPlus) {
11060 if (FunctionTemplate) {
11070 if (isFriend && FunctionTemplate &&
11071 FriendConstraintsDependOnEnclosingTemplate(NewFD)) {
11079 diag::err_friend_decl_with_enclosing_temp_constraint_must_be_def);
11084 if (FunctionTemplate) {
11087 return FunctionTemplate;
11091 CompleteMemberSpecialization(NewFD,
Previous);
11098 QualType ElemTy = PipeTy->getElementType();
11100 Diag(Param->getTypeSpecStartLoc(), diag::err_reference_pipe_type );
11107 Diag(Param->getTypeSpecStartLoc(),
11108 diag::err_wasm_table_as_function_parameter);
11116 if (
const auto *
attr = NewFD->
getAttr<AvailabilityAttr>()) {
11117 if (NewFD->
hasAttr<ConstructorAttr>()) {
11118 Diag(
attr->getLocation(), diag::warn_availability_on_static_initializer)
11120 NewFD->
dropAttr<AvailabilityAttr>();
11122 if (NewFD->
hasAttr<DestructorAttr>()) {
11123 Diag(
attr->getLocation(), diag::warn_availability_on_static_initializer)
11125 NewFD->
dropAttr<AvailabilityAttr>();
11136 if (
const auto *NBA = NewFD->
getAttr<NoBuiltinAttr>())
11140 Diag(NBA->getLocation(),
11141 diag::err_attribute_no_builtin_on_defaulted_deleted_function)
11142 << NBA->getSpelling();
11145 Diag(NBA->getLocation(), diag::err_attribute_no_builtin_on_non_definition)
11146 << NBA->getSpelling();
11166 const auto *Method = dyn_cast<CXXMethodDecl>(FD);
11170 if (
const auto *SAttr =
Parent->getAttr<CodeSegAttr>()) {
11181 while ((
Parent = dyn_cast<CXXRecordDecl>(
Parent->getParent()))) {
11182 if (
const auto *SAttr =
Parent->getAttr<CodeSegAttr>()) {
11201 bool IsDefinition) {
11204 if (!FD->
hasAttr<SectionAttr>() && IsDefinition &&
11205 CodeSegStack.CurrentValue)
11206 return SectionAttr::CreateImplicit(
11207 getASTContext(), CodeSegStack.CurrentValue->getString(),
11208 CodeSegStack.CurrentPragmaLocation, SectionAttr::Declspec_allocate);
11273 auto *VD = dyn_cast<ValueDecl>(D);
11274 auto *PrevVD = dyn_cast<ValueDecl>(PrevDecl);
11275 return !VD || !PrevVD ||
11276 canFullyTypeCheckRedeclaration(VD, PrevVD, VD->getType(),
11277 PrevVD->getType());
11285 const auto *TA = FD->
getAttr<TargetAttr>();
11286 const auto *TVA = FD->
getAttr<TargetVersionAttr>();
11289 "MultiVersion candidate requires a target or target_version attribute");
11301 for (
const auto &Feat : ParseInfo.
Features) {
11302 auto BareFeat = StringRef{Feat}.substr(1);
11303 if (Feat[0] ==
'-') {
11305 << Feature << (
"no-" + BareFeat).str();
11312 << Feature << BareFeat;
11320 TVA->getFeatures(Feats);
11321 for (
const auto &Feat : Feats) {
11324 << Feature << Feat;
11343 case attr::NonNull:
11344 case attr::NoThrow:
11353 const auto Diagnose = [FD, CausedFD, MVKind](
Sema &S,
const Attr *A) {
11354 S.
Diag(FD->
getLocation(), diag::err_multiversion_disallowed_other_attr)
11355 <<
static_cast<unsigned>(MVKind) << A;
11357 S.
Diag(CausedFD->
getLocation(), diag::note_multiversioning_caused_here);
11362 switch (A->getKind()) {
11363 case attr::CPUDispatch:
11364 case attr::CPUSpecific:
11367 return Diagnose(S, A);
11371 return Diagnose(S, A);
11373 case attr::TargetVersion:
11376 return Diagnose(S, A);
11378 case attr::TargetClones:
11381 return Diagnose(S, A);
11385 return Diagnose(S, A);
11398 bool ConstexprSupported,
bool CLinkageMayDiffer) {
11399 enum DoesntSupport {
11406 DefaultedFuncs = 6,
11407 ConstexprFuncs = 7,
11408 ConstevalFuncs = 8,
11420 if (NoProtoDiagID.
getDiagID() != 0 && OldFD &&
11423 Diag(NoteCausedDiagIDAt.first, NoteCausedDiagIDAt.second);
11431 if (!TemplatesSupported &&
11433 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11436 if (
const auto *NewCXXFD = dyn_cast<CXXMethodDecl>(NewFD)) {
11437 if (NewCXXFD->isVirtual())
11438 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11441 if (isa<CXXConstructorDecl>(NewCXXFD))
11442 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11445 if (isa<CXXDestructorDecl>(NewCXXFD))
11446 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11451 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11455 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11459 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11460 << (NewFD->
isConsteval() ? ConstevalFuncs : ConstexprFuncs);
11463 const auto *NewType = cast<FunctionType>(NewQType);
11464 QualType NewReturnType = NewType->getReturnType();
11467 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11473 const auto *OldType = cast<FunctionType>(OldQType);
11477 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC())
11480 QualType OldReturnType = OldType->getReturnType();
11482 if (OldReturnType != NewReturnType)
11483 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << ReturnType;
11486 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << ConstexprSpec;
11489 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << InlineSpec;
11492 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) <<
Linkage;
11497 if (CheckEquivalentExceptionSpec(
11516 bool IsCPUSpecificCPUDispatchMVKind =
11520 if (CausesMV && OldFD &&
11528 if (OldFD && CausesMV && OldFD->
isUsed(
false))
11529 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_after_used);
11532 OldFD, NewFD, S.
PDiag(diag::err_multiversion_noproto),
11534 S.
PDiag(diag::note_multiversioning_caused_here)),
11536 S.
PDiag(diag::err_multiversion_doesnt_support)
11537 <<
static_cast<unsigned>(MVKind)),
11539 S.
PDiag(diag::err_multiversion_diff)),
11541 !IsCPUSpecificCPUDispatchMVKind,
11554 "Function lacks multiversion attribute");
11555 const auto *TA = FD->
getAttr<TargetAttr>();
11556 const auto *TVA = FD->
getAttr<TargetVersionAttr>();
11559 if (TA && !TA->isDefaultVersion())
11596 To->
addAttr(TargetVersionAttr::CreateImplicit(
11603 bool &Redeclaration,
11613 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
11614 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
11615 const auto *OldTA = OldFD->
getAttr<TargetAttr>();
11616 const auto *OldTVA = OldFD->
getAttr<TargetVersionAttr>();
11619 if ((NewTA && !NewTA->isDefaultVersion() &&
11620 (!OldTA || OldTA->getFeaturesStr() == NewTA->getFeaturesStr())) ||
11621 (NewTVA && !NewTVA->isDefaultVersion() &&
11622 (!OldTVA || OldTVA->getName() == NewTVA->getName())))
11639 if ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
11640 (NewTVA && NewTVA->isDefaultVersion() && !OldTVA)) {
11641 Redeclaration =
true;
11649 S.
Diag(NewFD->
getLocation(), diag::note_multiversioning_caused_here);
11657 OldTA->getFeaturesStr());
11661 NewTA->getFeaturesStr());
11664 if (OldParsed == NewParsed) {
11674 OldTVA->getFeatures(Feats);
11677 NewTVA->getFeatures(NewFeats);
11678 llvm::sort(NewFeats);
11680 if (Feats == NewFeats) {
11688 for (
const auto *FD : OldFD->
redecls()) {
11689 const auto *CurTA = FD->
getAttr<TargetAttr>();
11690 const auto *CurTVA = FD->
getAttr<TargetVersionAttr>();
11694 ((NewTA && (!CurTA || CurTA->isInherited())) ||
11695 (NewTVA && (!CurTVA || CurTVA->isInherited())))) {
11697 << (NewTA ? 0 : 2);
11698 S.
Diag(NewFD->
getLocation(), diag::note_multiversioning_caused_here);
11706 Redeclaration =
false;
11745 const CPUDispatchAttr *NewCPUDisp,
const CPUSpecificAttr *NewCPUSpec,
11746 const TargetClonesAttr *NewClones,
bool &Redeclaration,
NamedDecl *&OldDecl,
11761 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
11762 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
11769 NewTA->getFeaturesStr());
11774 NewTVA->getFeatures(NewFeats);
11775 llvm::sort(NewFeats);
11778 bool UseMemberUsingDeclRules =
11781 bool MayNeedOverloadableChecks =
11790 if (MayNeedOverloadableChecks &&
11791 S.
IsOverload(NewFD, CurFD, UseMemberUsingDeclRules))
11794 switch (NewMVKind) {
11797 "Only target_clones can be omitted in subsequent declarations");
11800 const auto *CurTA = CurFD->
getAttr<TargetAttr>();
11801 if (CurTA->getFeaturesStr() == NewTA->getFeaturesStr()) {
11803 Redeclaration =
true;
11810 CurTA->getFeaturesStr());
11812 if (CurParsed == NewParsed) {
11821 if (
const auto *CurTVA = CurFD->
getAttr<TargetVersionAttr>()) {
11822 if (CurTVA->getName() == NewTVA->getName()) {
11824 Redeclaration =
true;
11829 CurTVA->getFeatures(CurFeats);
11830 llvm::sort(CurFeats);
11832 if (CurFeats == NewFeats) {
11838 }
else if (
const auto *CurClones = CurFD->
getAttr<TargetClonesAttr>()) {
11840 if (NewFeats.empty())
11843 for (
unsigned I = 0; I < CurClones->featuresStrs_size(); ++I) {
11845 CurClones->getFeatures(CurFeats, I);
11846 llvm::sort(CurFeats);
11848 if (CurFeats == NewFeats) {
11859 assert(NewClones &&
"MultiVersionKind does not match attribute type");
11860 if (
const auto *CurClones = CurFD->
getAttr<TargetClonesAttr>()) {
11861 if (CurClones->featuresStrs_size() != NewClones->featuresStrs_size() ||
11862 !std::equal(CurClones->featuresStrs_begin(),
11863 CurClones->featuresStrs_end(),
11864 NewClones->featuresStrs_begin())) {
11870 }
else if (
const auto *CurTVA = CurFD->
getAttr<TargetVersionAttr>()) {
11872 CurTVA->getFeatures(CurFeats);
11873 llvm::sort(CurFeats);
11876 if (CurFeats.empty())
11879 for (
unsigned I = 0; I < NewClones->featuresStrs_size(); ++I) {
11881 NewClones->getFeatures(NewFeats, I);
11882 llvm::sort(NewFeats);
11884 if (CurFeats == NewFeats) {
11893 Redeclaration =
true;
11900 const auto *CurCPUSpec = CurFD->
getAttr<CPUSpecificAttr>();
11901 const auto *CurCPUDisp = CurFD->
getAttr<CPUDispatchAttr>();
11906 CurFD->
hasAttr<CPUDispatchAttr>()) {
11907 if (CurCPUDisp->cpus_size() == NewCPUDisp->cpus_size() &&
11909 CurCPUDisp->cpus_begin(), CurCPUDisp->cpus_end(),
11910 NewCPUDisp->cpus_begin(),
11912 return Cur->getName() == New->getName();
11915 Redeclaration =
true;
11927 if (CurCPUSpec->cpus_size() == NewCPUSpec->cpus_size() &&
11929 CurCPUSpec->cpus_begin(), CurCPUSpec->cpus_end(),
11930 NewCPUSpec->cpus_begin(),
11932 return Cur->getName() == New->getName();
11935 Redeclaration =
true;
11943 if (CurII == NewII) {
11978 Redeclaration =
true;
11984 Redeclaration =
false;
11997 bool &Redeclaration,
NamedDecl *&OldDecl,
11999 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
12000 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
12001 const auto *NewCPUDisp = NewFD->
getAttr<CPUDispatchAttr>();
12002 const auto *NewCPUSpec = NewFD->
getAttr<CPUSpecificAttr>();
12003 const auto *NewClones = NewFD->
getAttr<TargetClonesAttr>();
12013 NewTVA->isDefaultVersion())) {
12014 S.
Diag(NewFD->
getLocation(), diag::err_multiversion_not_allowed_on_main);
12024 if (NewTA &&
T.isAArch64())
12028 if (NewTA &&
T.isRISCV())
12044 if (NewTVA || !OldFD->
getAttr<TargetVersionAttr>())
12052 NewFD->
addAttr(TargetVersionAttr::CreateImplicit(
12057 Redeclaration =
true;
12067 S.
Diag(NewFD->
getLocation(), diag::err_multiversion_required_in_redecl)
12080 if (OldFD->
isUsed(
false)) {
12082 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_after_used);
12098 NewCPUSpec, NewClones, Redeclaration,
12103 bool IsPure = NewFD->
hasAttr<PureAttr>();
12104 bool IsConst = NewFD->
hasAttr<ConstAttr>();
12107 if (!IsPure && !IsConst)
12114 if (IsPure && IsConst) {
12124 NewFD->
dropAttrs<PureAttr, ConstAttr>();
12147 bool IsMemberSpecialization,
12150 "Variably modified return types are not handled here");
12155 bool MergeTypeWithPrevious = !getLangOpts().CPlusPlus &&
12158 bool Redeclaration =
false;
12160 bool MayNeedOverloadableChecks =
false;
12171 if (shouldLinkPossiblyHiddenDecl(Candidate, NewFD)) {
12172 Redeclaration =
true;
12173 OldDecl = Candidate;
12176 MayNeedOverloadableChecks =
true;
12177 switch (CheckOverload(S, NewFD,
Previous, OldDecl,
12180 Redeclaration =
true;
12183 case Ovl_NonFunction:
12184 Redeclaration =
true;
12188 Redeclaration =
false;
12195 if (!Redeclaration &&
12200 Redeclaration =
true;
12201 OldDecl =
Previous.getFoundDecl();
12202 MergeTypeWithPrevious =
false;
12205 if (OldDecl->
hasAttr<OverloadableAttr>() ||
12206 NewFD->
hasAttr<OverloadableAttr>()) {
12207 if (IsOverload(NewFD, cast<FunctionDecl>(OldDecl),
false)) {
12208 MayNeedOverloadableChecks =
true;
12209 Redeclaration =
false;
12217 return Redeclaration;
12267 !MD->
isStatic() && !isa<CXXConstructorDecl>(MD) &&
12271 OldMD = dyn_cast_or_null<CXXMethodDecl>(OldDecl->
getAsFunction());
12272 if (!OldMD || !OldMD->
isStatic()) {
12282 if (!inTemplateInstantiation()) {
12286 AddConstLoc = getLocForEndOfToken(FTL.getRParenLoc());
12294 if (Redeclaration) {
12297 if (MergeFunctionDecl(NewFD, OldDecl, S, MergeTypeWithPrevious,
12300 return Redeclaration;
12307 dyn_cast<FunctionTemplateDecl>(OldDecl)) {
12308 auto *OldFD = OldTemplateDecl->getTemplatedDecl();
12311 assert(NewTemplateDecl &&
"Template/non-template mismatch");
12320 NewFD->
setAccess(OldTemplateDecl->getAccess());
12321 NewTemplateDecl->
setAccess(OldTemplateDecl->getAccess());
12326 if (IsMemberSpecialization &&
12329 assert(OldTemplateDecl->isMemberSpecialization());
12332 if (OldFD->isDeleted()) {
12334 assert(OldFD->getCanonicalDecl() == OldFD);
12336 OldFD->setDeletedAsWritten(
false);
12341 if (shouldLinkDependentDeclWithPrevious(NewFD, OldDecl)) {
12342 auto *OldFD = cast<FunctionDecl>(OldDecl);
12349 }
else if (!getLangOpts().
CPlusPlus && MayNeedOverloadableChecks &&
12350 !NewFD->
getAttr<OverloadableAttr>()) {
12354 return ND->hasAttr<OverloadableAttr>();
12356 "Non-redecls shouldn't happen without overloadable present");
12359 const auto *FD = dyn_cast<FunctionDecl>(ND);
12360 return FD && !FD->
hasAttr<OverloadableAttr>();
12363 if (OtherUnmarkedIter !=
Previous.end()) {
12365 diag::err_attribute_overloadable_multiple_unmarked_overloads);
12366 Diag((*OtherUnmarkedIter)->getLocation(),
12367 diag::note_attribute_overloadable_prev_overload)
12370 NewFD->
addAttr(OverloadableAttr::CreateImplicit(Context));
12374 if (LangOpts.OpenMP)
12375 OpenMP().ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(NewFD);
12382 CheckConstructor(Constructor);
12384 dyn_cast<CXXDestructorDecl>(NewFD)) {
12392 !Destructor->getFunctionObjectParameterType()->isDependentType()) {
12401 return Redeclaration;
12404 }
else if (
auto *Guide = dyn_cast<CXXDeductionGuideDecl>(NewFD)) {
12405 if (
auto *TD = Guide->getDescribedFunctionTemplate())
12406 CheckDeductionGuideTemplate(TD);
12411 Diag(Guide->getBeginLoc(), diag::err_deduction_guide_specialized)
12416 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(NewFD)) {
12417 if (!Method->isFunctionTemplateSpecialization() &&
12418 !Method->getDescribedFunctionTemplate() &&
12419 Method->isCanonicalDecl()) {
12420 AddOverriddenMethods(Method->getParent(), Method);
12426 diag::err_constrained_virtual_method);
12428 if (Method->isStatic())
12429 checkThisInStaticMemberFunctionType(Method);
12433 ActOnConversionDeclarator(Conversion);
12437 CheckOverloadedOperatorDeclaration(NewFD)) {
12439 return Redeclaration;
12444 CheckLiteralOperatorDeclaration(NewFD)) {
12446 return Redeclaration;
12452 if (!CurContext->isRecord())
12453 CheckCXXDefaultArguments(NewFD);
12466 Diag(NewFD->
getLocation(), diag::warn_return_value_udt) << NewFD << R;
12479 auto HasNoexcept = [&](
QualType T) ->
bool {
12490 if (FPT->isNothrow())
12496 bool AnyNoexcept = HasNoexcept(FPT->getReturnType());
12498 AnyNoexcept |= HasNoexcept(
T);
12501 diag::warn_cxx17_compat_exception_spec_in_signature)
12505 if (!Redeclaration && LangOpts.CUDA)
12514 bool UsesSM = NewFD->
hasAttr<ArmLocallyStreamingAttr>();
12515 bool UsesZA =
Attr &&
Attr->isNewZA();
12516 bool UsesZT0 =
Attr &&
Attr->isNewZT0();
12518 if (NewFD->
hasAttr<ArmLocallyStreamingAttr>()) {
12521 diag::warn_sme_locally_streaming_has_vl_args_returns)
12524 return P->getOriginalType()->isSizelessVectorType();
12527 diag::warn_sme_locally_streaming_has_vl_args_returns)
12540 if (UsesSM || UsesZA) {
12541 llvm::StringMap<bool> FeatureMap;
12543 if (!FeatureMap.contains(
"sme")) {
12546 diag::err_sme_definition_using_sm_in_non_sme_target);
12549 diag::err_sme_definition_using_za_in_non_sme_target);
12553 llvm::StringMap<bool> FeatureMap;
12555 if (!FeatureMap.contains(
"sme2")) {
12557 diag::err_sme_definition_using_zt0_in_non_sme2_target);
12562 return Redeclaration;
12575 ? diag::err_static_main : diag::warn_static_main)
12582 SourceRange NoreturnRange(NoreturnLoc, getLocForEndOfToken(NoreturnLoc));
12583 Diag(NoreturnLoc, diag::ext_noreturn_main);
12584 Diag(NoreturnLoc, diag::note_main_remove_noreturn)
12594 if (getLangOpts().
OpenCL) {
12596 << FD->
hasAttr<OpenCLKernelAttr>();
12603 if (getLangOpts().HLSL)
12607 assert(
T->
isFunctionType() &&
"function decl is not of function type");
12617 if (getLangOpts().GNUMode && !getLangOpts().CPlusPlus) {
12629 Diag(RTRange.
getBegin(), diag::note_main_change_return_type)
12651 if (isa<FunctionNoProtoType>(FT))
return;
12657 bool HasExtraParameters = (nparams > 3);
12669 HasExtraParameters =
false;
12671 if (HasExtraParameters) {
12684 for (
unsigned i = 0; i < nparams; ++i) {
12687 bool mismatch =
true;
12704 mismatch = !qs.
empty();
12733 if (
T.isWindowsGNUEnvironment())
12738 if (
T.isOSWindows() &&
T.getArch() == llvm::Triple::x86)
12746 assert(
T->
isFunctionType() &&
"function decl is not of function type");
12755 if (FD->
getName() !=
"DllMain")
12759 if (!hasExplicitCallingConv(
T)) {
12789 if (
Init->isValueDependent()) {
12790 assert(
Init->containsErrors() &&
12791 "Dependent code should only occur in error-recovery path.");
12794 const Expr *Culprit;
12795 if (
Init->isConstantInitializer(Context,
false, &Culprit))
12804 class SelfReferenceChecker
12810 bool isReferenceType;
12818 SelfReferenceChecker(
Sema &S,
Decl *OrigDecl) : Inherited(S.Context),
12819 S(S), OrigDecl(OrigDecl) {
12822 isReferenceType =
false;
12823 isInitList =
false;
12824 if (
ValueDecl *VD = dyn_cast<ValueDecl>(OrigDecl)) {
12825 isPODType = VD->getType().isPODType(S.
Context);
12827 isReferenceType = VD->getType()->isReferenceType();
12834 void CheckExpr(
Expr *E) {
12843 InitFieldIndex.push_back(0);
12844 for (
auto *Child : InitList->
children()) {
12845 CheckExpr(cast<Expr>(Child));
12846 ++InitFieldIndex.back();
12848 InitFieldIndex.pop_back();
12853 bool CheckInitListMemberExpr(
MemberExpr *E,
bool CheckReference) {
12856 bool ReferenceField =
false;
12860 FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
12863 Fields.push_back(FD);
12865 ReferenceField =
true;
12866 Base = ME->getBase()->IgnoreParenImpCasts();
12871 if (!DRE || DRE->
getDecl() != OrigDecl)
12875 if (CheckReference && !ReferenceField)
12880 for (
const FieldDecl *I : llvm::reverse(Fields))
12881 UsedFieldIndex.push_back(I->getFieldIndex());
12886 for (
auto UsedIter = UsedFieldIndex.begin(),
12887 UsedEnd = UsedFieldIndex.end(),
12888 OrigIter = InitFieldIndex.begin(),
12889 OrigEnd = InitFieldIndex.end();
12890 UsedIter != UsedEnd && OrigIter != OrigEnd; ++UsedIter, ++OrigIter) {
12891 if (*UsedIter < *OrigIter)
12893 if (*UsedIter > *OrigIter)
12898 HandleDeclRefExpr(DRE);
12905 void HandleValue(
Expr *E) {
12907 if (
DeclRefExpr* DRE = dyn_cast<DeclRefExpr>(E)) {
12908 HandleDeclRefExpr(DRE);
12913 Visit(CO->getCond());
12914 HandleValue(CO->getTrueExpr());
12915 HandleValue(CO->getFalseExpr());
12920 dyn_cast<BinaryConditionalOperator>(E)) {
12921 Visit(BCO->getCond());
12922 HandleValue(BCO->getFalseExpr());
12927 if (
Expr *SE = OVE->getSourceExpr())
12933 if (BO->getOpcode() == BO_Comma) {
12934 Visit(BO->getLHS());
12935 HandleValue(BO->getRHS());
12940 if (isa<MemberExpr>(E)) {
12942 if (CheckInitListMemberExpr(cast<MemberExpr>(E),
12950 if (!isa<FieldDecl>(ME->getMemberDecl()))
12952 Base = ME->getBase()->IgnoreParenImpCasts();
12955 HandleDeclRefExpr(DRE);
12965 if (isReferenceType)
12966 HandleDeclRefExpr(E);
12975 Inherited::VisitImplicitCastExpr(E);
12980 if (CheckInitListMemberExpr(E,
true ))
12990 bool Warn = (MD && !MD->
isStatic());
12993 if (!isa<FieldDecl>(ME->getMemberDecl()))
12995 Base = ME->getBase()->IgnoreParenImpCasts();
13000 HandleDeclRefExpr(DRE);
13012 if (isa<UnresolvedLookupExpr>(Callee))
13013 return Inherited::VisitCXXOperatorCallExpr(E);
13017 HandleValue(Arg->IgnoreParenImpCasts());
13034 Inherited::VisitUnaryOperator(E);
13042 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(ArgExpr))
13043 if (ILE->getNumInits() == 1)
13044 ArgExpr = ILE->getInit(0);
13046 if (ICE->getCastKind() == CK_NoOp)
13047 ArgExpr = ICE->getSubExpr();
13048 HandleValue(ArgExpr);
13051 Inherited::VisitCXXConstructExpr(E);
13057 HandleValue(E->
getArg(0));
13061 Inherited::VisitCallExpr(E);
13066 HandleValue(E->
getLHS());
13071 Inherited::VisitBinaryOperator(E);
13084 if (OrigDecl != ReferenceDecl)
return;
13086 if (isReferenceType) {
13087 diag = diag::warn_uninit_self_reference_in_reference_init;
13088 }
else if (cast<VarDecl>(OrigDecl)->isStaticLocal()) {
13089 diag = diag::warn_static_self_reference_in_init;
13090 }
else if (isa<TranslationUnitDecl>(OrigDecl->
getDeclContext()) ||
13093 diag = diag::warn_uninit_self_reference_in_init;
13107 static void CheckSelfReference(
Sema &S,
Decl* OrigDecl,
Expr *E,
13111 if (isa<ParmVarDecl>(OrigDecl))
13118 if (!DirectInit && !cast<VarDecl>(OrigDecl)->getType()->
isRecordType())
13120 if (ICE->getCastKind() == CK_LValueToRValue)
13121 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()))
13122 if (DRE->
getDecl() == OrigDecl)
13125 SelfReferenceChecker(S, OrigDecl).CheckExpr(E);
13132 struct VarDeclOrName {
13136 friend const Sema::SemaDiagnosticBuilder &
13137 operator<<(
const Sema::SemaDiagnosticBuilder &
Diag, VarDeclOrName VN) {
13138 return VN.VDecl ?
Diag << VN.VDecl :
Diag << VN.Name;
13148 bool IsInitCapture = !VDecl;
13150 "init captures are expected to be deduced prior to initialization");
13152 VarDeclOrName VN{VDecl, Name};
13155 assert(Deduced &&
"deduceVarTypeFromInitializer for non-deduced type");
13159 !isa_and_present<StringLiteral, InitListExpr>(Init)) {
13160 Diag(Range.getBegin(), diag::err_auto_not_allowed)
13168 assert(VDecl &&
"no init for init capture deduction?");
13172 if (!isa<DeducedTemplateSpecializationType>(Deduced) ||
13183 DeduceInits = Init;
13185 auto *PL = dyn_cast_if_present<ParenListExpr>(Init);
13187 DeduceInits = PL->exprs();
13189 if (isa<DeducedTemplateSpecializationType>(Deduced)) {
13190 assert(VDecl &&
"non-auto type for init capture deduction?");
13196 return DeduceTemplateSpecializationFromInitializer(TSI, Entity,
Kind,
13201 if (
auto *IL = dyn_cast<InitListExpr>(Init))
13202 DeduceInits = IL->inits();
13206 if (DeduceInits.empty()) {
13209 Diag(Init->getBeginLoc(), IsInitCapture
13210 ? diag::err_init_capture_no_expression
13211 : diag::err_auto_var_init_no_expression)
13212 << VN <<
Type << Range;
13216 if (DeduceInits.size() > 1) {
13217 Diag(DeduceInits[1]->getBeginLoc(),
13218 IsInitCapture ? diag::err_init_capture_multiple_expressions
13219 : diag::err_auto_var_init_multiple_expressions)
13220 << VN <<
Type << Range;
13224 Expr *DeduceInit = DeduceInits[0];
13225 if (
DirectInit && isa<InitListExpr>(DeduceInit)) {
13226 Diag(Init->getBeginLoc(), IsInitCapture
13227 ? diag::err_init_capture_paren_braces
13228 : diag::err_auto_var_init_paren_braces)
13229 << isa<InitListExpr>(Init) << VN <<
Type << Range;
13234 bool DefaultedAnyToId =
false;
13235 if (getLangOpts().DebuggerCastResultToId &&
13236 Init->getType() == Context.
UnknownAnyTy && !IsInitCapture) {
13238 if (Result.isInvalid()) {
13241 Init = Result.get();
13242 DefaultedAnyToId =
true;
13248 if (VDecl && isa<DecompositionDecl>(VDecl) &&
13252 Type.getQualifiers());
13260 if (!IsInitCapture)
13261 DiagnoseAutoDeductionFailure(VDecl, DeduceInit);
13262 else if (isa<InitListExpr>(Init))
13263 Diag(Range.getBegin(),
13264 diag::err_init_capture_deduction_failure_from_init_list)
13270 Diag(Range.getBegin(), diag::err_init_capture_deduction_failure)
13282 if (!inTemplateInstantiation() && !DefaultedAnyToId && !IsInitCapture &&
13285 Diag(Loc, diag::warn_auto_var_is_id) << VN << Range;
13293 assert(!Init || !Init->containsErrors());
13306 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(VDecl))
13309 if (getLangOpts().
OpenCL)
13310 deduceOpenCLAddressSpace(VDecl);
13317 MergeVarDeclTypes(VDecl, Old,
false);
13321 CheckVariableDeclarationType(VDecl);
13327 if (
auto *EWC = dyn_cast<ExprWithCleanups>(Init))
13328 Init = EWC->getSubExpr();
13330 if (
auto *CE = dyn_cast<ConstantExpr>(Init))
13331 Init = CE->getSubExpr();
13333 QualType InitType = Init->getType();
13336 "shouldn't be called if type doesn't have a non-trivial C struct");
13337 if (
auto *ILE = dyn_cast<InitListExpr>(Init)) {
13338 for (
auto *I : ILE->inits()) {
13339 if (!I->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion() &&
13340 !I->getType().hasNonTrivialToPrimitiveCopyCUnion())
13343 checkNonTrivialCUnionInInitializer(I, SL.
isValid() ? SL : Loc);
13348 if (isa<ImplicitValueInitExpr>(Init)) {
13350 checkNonTrivialCUnion(InitType, Loc, NTCUC_DefaultInitializedObject,
13358 checkNonTrivialCUnion(InitType, Loc, NTCUC_CopyInit, NTCUK_Copy);
13364 bool shouldIgnoreForRecordTriviality(
const FieldDecl *FD) {
13370 return FD->
hasAttr<UnavailableAttr>();
13373 struct DiagNonTrivalCUnionDefaultInitializeVisitor
13380 DiagNonTrivalCUnionDefaultInitializeVisitor(
13383 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
13386 const FieldDecl *FD,
bool InNonTrivialUnion) {
13389 InNonTrivialUnion);
13390 return Super::visitWithKind(PDIK, QT, FD, InNonTrivialUnion);
13394 bool InNonTrivialUnion) {
13395 if (InNonTrivialUnion)
13397 << 1 << 0 << QT << FD->
getName();
13401 if (InNonTrivialUnion)
13403 << 1 << 0 << QT << FD->
getName();
13409 if (OrigLoc.isValid()) {
13410 bool IsUnion =
false;
13411 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
13412 IsUnion = OrigRD->isUnion();
13413 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
13414 << 0 << OrigTy << IsUnion << UseContext;
13418 InNonTrivialUnion =
true;
13421 if (InNonTrivialUnion)
13426 if (!shouldIgnoreForRecordTriviality(FD))
13427 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
13440 struct DiagNonTrivalCUnionDestructedTypeVisitor
13445 DiagNonTrivalCUnionDestructedTypeVisitor(
13448 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
13451 const FieldDecl *FD,
bool InNonTrivialUnion) {
13454 InNonTrivialUnion);
13455 return Super::visitWithKind(DK, QT, FD, InNonTrivialUnion);
13459 bool InNonTrivialUnion) {
13460 if (InNonTrivialUnion)
13462 << 1 << 1 << QT << FD->
getName();
13466 if (InNonTrivialUnion)
13468 << 1 << 1 << QT << FD->
getName();
13474 if (OrigLoc.isValid()) {
13475 bool IsUnion =
false;
13476 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
13477 IsUnion = OrigRD->isUnion();
13478 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
13479 << 1 << OrigTy << IsUnion << UseContext;
13483 InNonTrivialUnion =
true;
13486 if (InNonTrivialUnion)
13491 if (!shouldIgnoreForRecordTriviality(FD))
13492 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
13497 bool InNonTrivialUnion) {}
13507 struct DiagNonTrivalCUnionCopyVisitor
13514 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
13517 const FieldDecl *FD,
bool InNonTrivialUnion) {
13520 InNonTrivialUnion);
13521 return Super::visitWithKind(PCK, QT, FD, InNonTrivialUnion);
13525 bool InNonTrivialUnion) {
13526 if (InNonTrivialUnion)
13528 << 1 << 2 << QT << FD->
getName();
13532 if (InNonTrivialUnion)
13534 << 1 << 2 << QT << FD->
getName();
13540 if (OrigLoc.isValid()) {
13541 bool IsUnion =
false;
13542 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
13543 IsUnion = OrigRD->isUnion();
13544 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
13545 << 2 << OrigTy << IsUnion << UseContext;
13549 InNonTrivialUnion =
true;
13552 if (InNonTrivialUnion)
13557 if (!shouldIgnoreForRecordTriviality(FD))
13558 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
13562 const FieldDecl *FD,
bool InNonTrivialUnion) {}
13565 bool InNonTrivialUnion) {}
13579 unsigned NonTrivialKind) {
13583 "shouldn't be called if type doesn't have a non-trivial C union");
13585 if ((NonTrivialKind & NTCUK_Init) &&
13587 DiagNonTrivalCUnionDefaultInitializeVisitor(QT, Loc, UseContext, *
this)
13588 .
visit(QT,
nullptr,
false);
13589 if ((NonTrivialKind & NTCUK_Destruct) &&
13591 DiagNonTrivalCUnionDestructedTypeVisitor(QT, Loc, UseContext, *
this)
13592 .visit(QT,
nullptr,
false);
13594 DiagNonTrivalCUnionCopyVisitor(QT, Loc, UseContext, *
this)
13595 .visit(QT,
nullptr,
false);
13605 CorrectDelayedTyposInExpr(Init, dyn_cast_or_null<VarDecl>(RealDecl));
13609 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(RealDecl)) {
13611 Diag(Method->getLocation(), diag::err_member_function_initialization)
13612 << Method->getDeclName() << Init->getSourceRange();
13613 Method->setInvalidDecl();
13617 VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
13619 assert(!isa<FieldDecl>(RealDecl) &&
"field init shouldn't get here");
13626 if (Init && !Init->getType().isNull() &&
13627 Init->getType()->isWebAssemblyTableType()) {
13628 Diag(Init->getExprLoc(), diag::err_wasm_table_art) << 0;
13638 ExprResult Res = CorrectDelayedTyposInExpr(Init, VDecl);
13653 if (DeduceVariableDeclarationType(VDecl,
DirectInit, Init))
13659 Diag(VDecl->
getLocation(), diag::err_attribute_dllimport_data_definition);
13680 BaseDeclType =
Array->getElementType();
13681 if (RequireCompleteType(VDecl->
getLocation(), BaseDeclType,
13682 diag::err_typecheck_decl_incomplete_type)) {
13689 diag::err_abstract_type_in_decl,
13690 AbstractVariableType))
13696 if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
13699 !VDecl->
isTemplated() && !isa<VarTemplateSpecializationDecl>(VDecl)) {
13708 if (Def != VDecl &&
13711 checkVarDeclRedefinition(Def, VDecl))
13728 Diag(Init->getExprLoc(), diag::err_static_data_member_reinitialization)
13731 diag::note_previous_initializer)
13737 setFunctionHasBranchProtectedScope();
13739 if (DiagnoseUnexpandedParameterPack(Init, UPPC_Initializer)) {
13754 if (SYCL().isSYCLEsimdPrivateGlobal(VDecl)) {
13761 if (VDecl->
hasAttr<LoaderUninitializedAttr>()) {
13762 Diag(VDecl->
getLocation(), diag::err_loader_uninitialized_cant_init);
13776 if (Result.isInvalid()) {
13780 Init = Result.get();
13784 ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init);
13785 bool IsParenListInit =
false;
13797 for (
size_t Idx = 0; Idx < Args.size(); ++Idx) {
13799 Args[Idx], VDecl,
true,
13802 return Init.Failed() ?
ExprError() : E;
13806 }
else if (Res.
get() != Args[Idx]) {
13807 Args[Idx] = Res.
get();
13817 if (Result.isInvalid()) {
13821 CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), Args);
13831 if (isa<DecompositionDecl>(VDecl))
13836 Init = Result.getAs<
Expr>();
13837 IsParenListInit = !InitSeq.
steps().empty() &&
13841 if (Init && !Init->getType().isNull() &&
13842 !Init->getType()->isDependentType() && !VDeclType->
isDependentType() &&
13861 CheckSelfReference(*
this, RealDecl, Init,
DirectInit);
13873 if (VDecl->
hasAttr<BlocksAttr>())
13874 checkRetainCycles(VDecl, Init);
13886 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
13887 Init->getBeginLoc()))
13888 FSI->markSafeWeakUse(Init);
13905 if (Result.isInvalid()) {
13909 Init = Result.get();
13922 CheckForConstantInitializer(Init);
13931 CheckForConstantInitializer(Init);
13938 isa<InitListExpr>(Init)) {
13939 CheckForConstantInitializer(Init, diag::ext_aggregate_init_not_constant);
13942 if (
auto *E = dyn_cast<ExprWithCleanups>(Init))
13943 if (
auto *BE = dyn_cast<BlockExpr>(E->getSubExpr()->
IgnoreParens()))
13945 BE->getBlockDecl()->setCanAvoidCopyToHeap();
13980 << Init->getSourceRange();
13991 else if (Init->isValueDependent())
13993 else if (Init->isIntegerConstantExpr(Context, &Loc))
13995 else if (Init->getType()->isScopedEnumeralType() &&
13996 Init->isCXX11ConstantExpr(Context))
13998 else if (Init->isEvaluatable(Context)) {
14001 Diag(Loc, diag::ext_in_class_initializer_non_constant)
14002 << Init->getSourceRange();
14006 Diag(Loc, diag::err_in_class_initializer_non_constant)
14007 << Init->getSourceRange();
14017 diag::ext_in_class_initializer_float_type_cxx11)
14018 << DclT << Init->getSourceRange();
14020 diag::note_in_class_initializer_float_type_cxx11)
14023 Diag(VDecl->
getLocation(), diag::ext_in_class_initializer_float_type)
14024 << DclT << Init->getSourceRange();
14026 if (!Init->isValueDependent() && !Init->isEvaluatable(Context)) {
14027 Diag(Init->getExprLoc(), diag::err_in_class_initializer_non_constant)
14028 << Init->getSourceRange();
14035 Diag(VDecl->
getLocation(), diag::err_in_class_initializer_literal_type)
14036 << DclT << Init->getSourceRange()
14042 << DclT << Init->getSourceRange();
14072 CheckForConstantInitializer(Init);
14075 QualType InitType = Init->getType();
14076 if (!InitType.
isNull() &&
14079 checkNonTrivialCUnionInInitializer(Init, Init->getExprLoc());
14095 if (CXXDirectInit) {
14096 assert(
DirectInit &&
"Call-style initializer must be direct init.");
14104 if (LangOpts.OpenMP &&
14107 DeclsToCheckForDeferredDiags.insert(VDecl);
14108 CheckCompleteVariableDeclaration(VDecl);
14120 VarDecl *VD = dyn_cast<VarDecl>(D);
14124 if (
auto *DD = dyn_cast<DecompositionDecl>(D))
14125 for (
auto *BD : DD->bindings())
14126 BD->setInvalidDecl();
14140 diag::err_typecheck_decl_incomplete_type)) {
14146 if (RequireNonAbstractType(VD->
getLocation(), Ty,
14147 diag::err_abstract_type_in_decl,
14148 AbstractVariableType)) {
14162 if (
VarDecl *Var = dyn_cast<VarDecl>(RealDecl)) {
14166 if (isa<DecompositionDecl>(RealDecl)) {
14167 Diag(Var->getLocation(), diag::err_decomp_decl_requires_init) << Var;
14168 Var->setInvalidDecl();
14173 DeduceVariableDeclarationType(Var,
false,
nullptr))
14182 if (Var->isConstexpr() && !Var->isThisDeclarationADefinition() &&
14183 !Var->isThisDeclarationADemotedDefinition()) {
14184 if (Var->isStaticDataMember()) {
14189 Diag(Var->getLocation(),
14190 diag::err_constexpr_static_mem_var_requires_init)
14192 Var->setInvalidDecl();
14196 Diag(Var->getLocation(), diag::err_invalid_constexpr_var_decl);
14197 Var->setInvalidDecl();
14204 if (!Var->isInvalidDecl() &&
14206 Var->getStorageClass() !=
SC_Extern && !Var->getInit()) {
14207 bool HasConstExprDefaultConstructor =
false;
14208 if (
CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) {
14209 for (
auto *Ctor : RD->ctors()) {
14210 if (Ctor->isConstexpr() && Ctor->getNumParams() == 0 &&
14211 Ctor->getMethodQualifiers().getAddressSpace() ==
14213 HasConstExprDefaultConstructor =
true;
14217 if (!HasConstExprDefaultConstructor) {
14218 Diag(Var->getLocation(), diag::err_opencl_constant_no_init);
14219 Var->setInvalidDecl();
14224 if (!Var->isInvalidDecl() && RealDecl->
hasAttr<LoaderUninitializedAttr>()) {
14225 if (Var->getStorageClass() ==
SC_Extern) {
14226 Diag(Var->getLocation(), diag::err_loader_uninitialized_extern_decl)
14228 Var->setInvalidDecl();
14231 if (RequireCompleteType(Var->getLocation(), Var->getType(),
14232 diag::err_typecheck_decl_incomplete_type)) {
14233 Var->setInvalidDecl();
14236 if (
CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) {
14237 if (!RD->hasTrivialDefaultConstructor()) {
14238 Diag(Var->getLocation(), diag::err_loader_uninitialized_trivial_ctor);
14239 Var->setInvalidDecl();
14249 Var->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion())
14250 checkNonTrivialCUnion(Var->getType(), Var->getLocation(),
14251 NTCUC_DefaultInitializedObject, NTCUK_Init);
14256 if (!Var->isStaticDataMember() || !Var->getAnyInitializer())
14272 !Var->hasLinkage() && !Var->isInvalidDecl() &&
14273 RequireCompleteType(Var->getLocation(),
Type,
14274 diag::err_typecheck_decl_incomplete_type))
14275 Var->setInvalidDecl();
14279 RequireNonAbstractType(Var->getLocation(),
Type,
14280 diag::err_abstract_type_in_decl,
14281 AbstractVariableType))
14282 Var->setInvalidDecl();
14285 Diag(Var->getLocation(), diag::warn_private_extern);
14286 Diag(Var->getLocation(), diag::note_private_extern);
14290 !Var->isInvalidDecl())
14291 ExternalDeclarations.push_back(Var);
14301 if (!Var->isInvalidDecl()) {
14304 if (RequireCompleteSizedType(
14305 Var->getLocation(), ArrayT->getElementType(),
14306 diag::err_array_incomplete_or_sizeless_type))
14307 Var->setInvalidDecl();
14308 }
else if (Var->getStorageClass() ==
SC_Static) {
14318 if (Var->isFirstDecl())
14319 RequireCompleteType(Var->getLocation(),
Type,
14320 diag::ext_typecheck_decl_incomplete_type);
14325 if (!Var->isInvalidDecl())
14326 TentativeDefinitions.push_back(Var);
14333 if (Var->isConstexpr())
14334 Diag(Var->getLocation(), diag::err_constexpr_var_requires_const_init)
14337 Diag(Var->getLocation(),
14338 diag::err_typecheck_incomplete_array_needs_initializer);
14339 Var->setInvalidDecl();
14346 Diag(Var->getLocation(), diag::err_reference_var_requires_init)
14347 << Var <<
SourceRange(Var->getLocation(), Var->getLocation());
14356 if (Var->isInvalidDecl())
14359 if (!Var->hasAttr<AliasAttr>()) {
14360 if (RequireCompleteType(Var->getLocation(),
14362 diag::err_typecheck_decl_incomplete_type)) {
14363 Var->setInvalidDecl();
14371 if (RequireNonAbstractType(Var->getLocation(),
Type,
14372 diag::err_abstract_type_in_decl,
14373 AbstractVariableType)) {
14374 Var->setInvalidDecl();
14388 if (getLangOpts().
CPlusPlus && Var->hasLocalStorage()) {
14395 if (!CXXRecord->isPOD())
14396 setFunctionHasBranchProtectedScope();
14401 if (getLangOpts().
OpenCL &&
14406 if (SYCL().isSYCLEsimdPrivateGlobal(Var))
14431 Var->setInit(MaybeCreateExprWithCleanups(Init.get()));
14434 }
else if (Init.isInvalid()) {
14438 CreateRecoveryExpr(Var->getLocation(), Var->getLocation(), {});
14443 CheckCompleteVariableDeclaration(Var);
14452 VarDecl *VD = dyn_cast<VarDecl>(D);
14511 const char *PrevSpec;
14514 getPrintingPolicy());
14522 Decl *Var = ActOnDeclarator(S, D);
14523 cast<VarDecl>(Var)->setCXXForRangeDecl(
true);
14524 FinalizeDeclaration(Var);
14525 return ActOnDeclStmt(FinalizeDeclaratorGroup(S, DS, Var), IdentLoc,
14531 if (
var->isInvalidDecl())
return;
14533 CUDA().MaybeAddConstantAttr(
var);
14535 if (getLangOpts().
OpenCL) {
14538 if (
var->getTypeSourceInfo()->getType()->isBlockPointerType() &&
14540 Diag(
var->getLocation(), diag::err_opencl_invalid_block_declaration)
14542 var->setInvalidDecl();
14547 if (getLangOpts().SYCLIsDevice)
14548 SYCL().checkSYCLDeviceVarDecl(
var);
14552 if (getLangOpts().ObjC &&
14553 var->hasLocalStorage()) {
14554 switch (
var->getType().getObjCLifetime()) {
14562 setFunctionHasBranchProtectedScope();
14567 if (
var->hasLocalStorage() &&
14569 setFunctionHasBranchProtectedScope();
14576 if (
var->isThisDeclarationADefinition() &&
14577 var->getDeclContext()->getRedeclContext()->isFileContext() &&
14578 var->isExternallyVisible() &&
var->hasLinkage() &&
14579 !
var->isInline() && !
var->getDescribedVarTemplate() &&
14581 !isa<VarTemplatePartialSpecializationDecl>(
var) &&
14583 !getDiagnostics().isIgnored(diag::warn_missing_variable_declarations,
14584 var->getLocation())) {
14591 Diag(
var->getLocation(), diag::warn_missing_variable_declarations) <<
var;
14592 Diag(
var->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage)
14598 std::optional<bool> CacheHasConstInit;
14599 const Expr *CacheCulprit =
nullptr;
14600 auto checkConstInit = [&]()
mutable {
14601 if (!CacheHasConstInit)
14602 CacheHasConstInit =
var->getInit()->isConstantInitializer(
14603 Context,
var->getType()->isReferenceType(), &CacheCulprit);
14604 return *CacheHasConstInit;
14608 if (
var->getType().isDestructedType()) {
14612 Diag(
var->getLocation(), diag::err_thread_nontrivial_dtor);
14614 Diag(
var->getLocation(), diag::note_use_thread_local);
14615 }
else if (getLangOpts().
CPlusPlus &&
var->hasInit()) {
14616 if (!checkConstInit()) {
14624 Diag(
var->getLocation(), diag::note_use_thread_local);
14630 if (!
var->getType()->isStructureType() &&
var->hasInit() &&
14631 isa<InitListExpr>(
var->getInit())) {
14632 const auto *ILE = cast<InitListExpr>(
var->getInit());
14633 unsigned NumInits = ILE->getNumInits();
14635 for (
unsigned I = 0; I < NumInits; ++I) {
14636 const auto *Init = ILE->getInit(I);
14639 const auto *SL = dyn_cast<StringLiteral>(Init->IgnoreImpCasts());
14643 unsigned NumConcat = SL->getNumConcatenated();
14647 if (NumConcat == 2 && !SL->getBeginLoc().isMacroID()) {
14648 bool OnlyOneMissingComma =
true;
14649 for (
unsigned J = I + 1; J < NumInits; ++J) {
14650 const auto *Init = ILE->getInit(J);
14653 const auto *SLJ = dyn_cast<StringLiteral>(Init->IgnoreImpCasts());
14654 if (!SLJ || SLJ->getNumConcatenated() > 1) {
14655 OnlyOneMissingComma =
false;
14660 if (OnlyOneMissingComma) {
14662 for (
unsigned i = 0; i < NumConcat - 1; ++i)
14664 PP.getLocForEndOfToken(SL->getStrTokenLoc(i)),
","));
14666 Diag(SL->getStrTokenLoc(1),
14667 diag::warn_concatenated_literal_array_init)
14669 Diag(SL->getBeginLoc(),
14670 diag::note_concatenated_string_literal_silence);
14681 if (
var->hasAttr<BlocksAttr>())
14682 getCurFunction()->addByrefBlockVar(
var);
14685 bool GlobalStorage =
var->hasGlobalStorage();
14686 bool IsGlobal = GlobalStorage && !
var->isStaticLocal();
14688 bool HasConstInit =
true;
14690 if (getLangOpts().
C23 &&
var->isConstexpr() && !Init)
14691 Diag(
var->getLocation(), diag::err_constexpr_var_requires_const_init)
14695 if ((getLangOpts().
CPlusPlus || (getLangOpts().
C23 &&
var->isConstexpr())) &&
14696 !
type->isDependentType() && Init && !Init->isValueDependent() &&
14697 (GlobalStorage ||
var->isConstexpr() ||
14698 var->mightBeUsableInConstantExpressions(Context))) {
14710 HasConstInit = checkConstInit();
14714 if (HasConstInit) {
14715 (void)
var->checkForConstantInitialization(Notes);
14717 }
else if (CacheCulprit) {
14718 Notes.emplace_back(CacheCulprit->
getExprLoc(),
14719 PDiag(diag::note_invalid_subexpr_in_const_expr));
14724 HasConstInit =
var->checkForConstantInitialization(Notes);
14727 if (HasConstInit) {
14729 }
else if (
var->isConstexpr()) {
14733 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
14734 diag::note_invalid_subexpr_in_const_expr) {
14735 DiagLoc = Notes[0].first;
14738 Diag(DiagLoc, diag::err_constexpr_var_requires_const_init)
14739 <<
var << Init->getSourceRange();
14740 for (
unsigned I = 0, N = Notes.size(); I != N; ++I)
14741 Diag(Notes[I].first, Notes[I].second);
14742 }
else if (GlobalStorage &&
var->hasAttr<ConstInitAttr>()) {
14743 auto *
Attr =
var->getAttr<ConstInitAttr>();
14744 Diag(
var->getLocation(), diag::err_require_constant_init_failed)
14745 << Init->getSourceRange();
14748 for (
auto &it : Notes)
14749 Diag(it.first, it.second);
14750 }
else if (IsGlobal &&
14751 !getDiagnostics().isIgnored(diag::warn_global_constructor,
14752 var->getLocation())) {
14761 if (!checkConstInit())
14762 Diag(
var->getLocation(), diag::warn_global_constructor)
14763 << Init->getSourceRange();
14769 if (GlobalStorage &&
var->isThisDeclarationADefinition() &&
14770 !inTemplateInstantiation()) {
14775 std::optional<QualType::NonConstantStorageReason> Reason;
14776 if (HasConstInit &&
14777 !(Reason =
var->getType().isNonConstantStorage(Context,
true,
false))) {
14778 Stack = &ConstSegStack;
14781 Stack =
var->hasInit() && HasConstInit ? &DataSegStack : &BSSSegStack;
14783 if (
const SectionAttr *SA =
var->getAttr<SectionAttr>()) {
14786 UnifySection(SA->getName(), SectionFlags,
var);
14787 }
else if (Stack->CurrentValue) {
14788 if (Stack != &ConstSegStack && MSVCEnv &&
14789 ConstSegStack.CurrentValue != ConstSegStack.DefaultValue &&
14790 var->getType().isConstQualified()) {
14792 NonConstNonReferenceType) &&
14793 "This case should've already been handled elsewhere");
14794 Diag(
var->getLocation(), diag::warn_section_msvc_compat)
14795 <<
var << ConstSegStack.CurrentValue << (
int)(!HasConstInit
14800 auto SectionName = Stack->CurrentValue->getString();
14801 var->addAttr(SectionAttr::CreateImplicit(Context, SectionName,
14802 Stack->CurrentPragmaLocation,
14803 SectionAttr::Declspec_allocate));
14804 if (UnifySection(SectionName, SectionFlags,
var))
14805 var->dropAttr<SectionAttr>();
14811 if (CurInitSeg &&
var->getInit())
14812 var->addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(),
14817 if (!getLangOpts().CPlusPlus) {
14826 if (!
type->isDependentType())
14836 if (
auto *DD = dyn_cast<DecompositionDecl>(
var))
14837 CheckCompleteDecompositionDeclaration(DD);
14849 !FD->
hasAttr<DLLExportStaticLocalAttr>() &&
14850 !FD->
hasAttr<DLLImportStaticLocalAttr>()) {
14859 auto *NewAttr = cast<InheritableAttr>(A->clone(getASTContext()));
14860 NewAttr->setInherited(
true);
14862 }
else if (
Attr *A = FD->
getAttr<DLLExportStaticLocalAttr>()) {
14863 auto *NewAttr = DLLExportAttr::CreateImplicit(getASTContext(), *A);
14864 NewAttr->setInherited(
true);
14869 if (!FD->
hasAttr<DLLExportAttr>())
14872 }
else if (
Attr *A = FD->
getAttr<DLLImportStaticLocalAttr>()) {
14873 auto *NewAttr = DLLImportAttr::CreateImplicit(getASTContext(), *A);
14874 NewAttr->setInherited(
true);
14903 ParsingInitForAutoVars.erase(ThisDecl);
14905 VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDecl);
14911 !inTemplateInstantiation() && !VD->
hasAttr<SectionAttr>()) {
14912 if (PragmaClangBSSSection.Valid)
14913 VD->
addAttr(PragmaClangBSSSectionAttr::CreateImplicit(
14914 Context, PragmaClangBSSSection.SectionName,
14915 PragmaClangBSSSection.PragmaLocation));
14916 if (PragmaClangDataSection.Valid)
14917 VD->
addAttr(PragmaClangDataSectionAttr::CreateImplicit(
14918 Context, PragmaClangDataSection.SectionName,
14919 PragmaClangDataSection.PragmaLocation));
14920 if (PragmaClangRodataSection.Valid)
14921 VD->
addAttr(PragmaClangRodataSectionAttr::CreateImplicit(
14922 Context, PragmaClangRodataSection.SectionName,
14923 PragmaClangRodataSection.PragmaLocation));
14924 if (PragmaClangRelroSection.Valid)
14925 VD->
addAttr(PragmaClangRelroSectionAttr::CreateImplicit(
14926 Context, PragmaClangRelroSection.SectionName,
14927 PragmaClangRelroSection.PragmaLocation));
14930 if (
auto *DD = dyn_cast<DecompositionDecl>(ThisDecl)) {
14931 for (
auto *BD : DD->bindings()) {
14932 FinalizeDeclaration(BD);
14939 CheckStaticLocalForDllExport(VD);
14942 CheckThreadLocalForLargeAlignment(VD);
14949 if (getLangOpts().
CUDA)
14950 CUDA().checkAllowedInitializer(VD);
14956 if (
const auto *IA = dyn_cast_or_null<DLLImportAttr>(DLLAttr)) {
14963 bool IsClassTemplateMember =
14964 isa<ClassTemplatePartialSpecializationDecl>(Context) ||
14965 Context->getDescribedClassTemplate();
14968 IsClassTemplateMember
14969 ? diag::warn_attribute_dllimport_static_field_definition
14970 : diag::err_attribute_dllimport_static_field_definition);
14971 Diag(IA->getLocation(), diag::note_attribute);
14972 if (!IsClassTemplateMember)
15000 if (RetainAttr *
Attr = VD->
getAttr<RetainAttr>()) {
15012 AddPushedVisibilityAttribute(VD);
15015 if (VD->
isFileVarDecl() && !isa<VarTemplatePartialSpecializationDecl>(VD))
15016 MarkUnusedFileScopedDecl(VD);
15020 if (!VD->
hasAttr<TypeTagForDatatypeAttr>() ||
15024 for (
const auto *I : ThisDecl->
specific_attrs<TypeTagForDatatypeAttr>()) {
15026 if (!MagicValueExpr) {
15029 std::optional<llvm::APSInt> MagicValueInt;
15031 Diag(I->getRange().getBegin(),
15032 diag::err_type_tag_for_datatype_not_ice)
15036 if (MagicValueInt->getActiveBits() > 64) {
15037 Diag(I->getRange().getBegin(),
15038 diag::err_type_tag_for_datatype_too_large)
15042 uint64_t MagicValue = MagicValueInt->getZExtValue();
15043 RegisterTypeTagForDatatype(I->getArgumentKind(),
15045 I->getMatchingCType(),
15046 I->getLayoutCompatible(),
15047 I->getMustBeNull());
15052 auto *VD = dyn_cast<VarDecl>(DD);
15053 return VD && !VD->getType()->hasAutoForTrailingReturnType();
15065 bool DiagnosedMultipleDecomps =
false;
15067 bool DiagnosedNonDeducedAuto =
false;
15069 for (
unsigned i = 0, e =
Group.size(); i != e; ++i) {
15073 if (
auto *VD = dyn_cast<VarDecl>(D);
15074 LangOpts.OpenMP && VD && VD->hasAttr<OMPDeclareTargetDeclAttr>() &&
15075 VD->hasGlobalStorage())
15076 OpenMP().ActOnOpenMPDeclareTargetInitializer(D);
15079 if (
auto *DD = dyn_cast<DeclaratorDecl>(D)) {
15080 if (!FirstDeclaratorInGroup)
15081 FirstDeclaratorInGroup = DD;
15082 if (!FirstDecompDeclaratorInGroup)
15083 FirstDecompDeclaratorInGroup = dyn_cast<DecompositionDecl>(D);
15086 FirstNonDeducedAutoInGroup = DD;
15088 if (FirstDeclaratorInGroup != DD) {
15091 if (FirstDecompDeclaratorInGroup && !DiagnosedMultipleDecomps) {
15093 diag::err_decomp_decl_not_alone)
15095 << DD->getSourceRange();
15096 DiagnosedMultipleDecomps =
true;
15102 if (FirstNonDeducedAutoInGroup && !DiagnosedNonDeducedAuto) {
15104 diag::err_auto_non_deduced_not_alone)
15105 << FirstNonDeducedAutoInGroup->
getType()
15108 << DD->getSourceRange();
15109 DiagnosedNonDeducedAuto =
true;
15114 Decls.push_back(D);
15120 handleTagNumbering(Tag, S);
15121 if (FirstDeclaratorInGroup && !Tag->hasNameForLinkage() &&
15127 return BuildDeclaratorGroup(Decls);
15137 if (
Group.size() > 1) {
15139 VarDecl *DeducedDecl =
nullptr;
15140 for (
unsigned i = 0, e =
Group.size(); i != e; ++i) {
15151 auto *AT = dyn_cast<AutoType>(DT);
15153 diag::err_auto_different_deductions)
15154 << (AT ? (
unsigned)AT->getKeyword() : 3) << Deduced
15167 ActOnDocumentableDecls(
Group);
15169 return DeclGroupPtrTy::make(
15174 ActOnDocumentableDecls(D);
15182 if (Diags.isIgnored(diag::warn_doc_param_not_found,
15183 Group[0]->getLocation()) &&
15184 Diags.isIgnored(diag::warn_unknown_comment_command_name,
15185 Group[0]->getLocation()))
15188 if (
Group.size() >= 2) {
15197 if (MaybeTagDecl && isa<TagDecl>(MaybeTagDecl)) {
15214 CheckExtraCXXDefaultArguments(D);
15236 << GetNameForDeclarator(D).getName();
15249 if (!ExplicitThisLoc.
isValid())
15252 "explicit parameter in non-cplusplus mode");
15254 S.
Diag(ExplicitThisLoc, diag::err_cxx20_deducing_this)
15255 <<
P->getSourceRange();
15259 if (
P->isParameterPack()) {
15260 S.
Diag(
P->getBeginLoc(), diag::err_explicit_object_parameter_pack)
15261 <<
P->getSourceRange();
15264 P->setExplicitObjectParameterLoc(ExplicitThisLoc);
15266 LSI->ExplicitObjectParameter =
P;
15285 getLangOpts().
CPlusPlus17 ? diag::ext_register_storage_class
15286 : diag::warn_deprecated_register)
15294 diag::err_invalid_storage_class_in_func_decl);
15303 << getLangOpts().CPlusPlus17;
15308 DiagnoseFunctionSpecifiers(DS);
15310 CheckFunctionOrTemplateParamDeclarator(S, D);
15327 PrevDecl =
nullptr;
15329 if (PrevDecl && S->isDeclScope(PrevDecl)) {
15352 assert(S->isFunctionPrototypeScope());
15353 assert(S->getFunctionPrototypeDepth() >= 1);
15355 S->getNextFunctionPrototypeIndex());
15360 IdResolver.AddDecl(New);
15362 ProcessDeclAttributes(S, New, D);
15369 if (New->
hasAttr<BlocksAttr>()) {
15373 if (getLangOpts().
OpenCL)
15374 deduceOpenCLAddressSpace(New);
15397 if (inTemplateInstantiation())
15403 !
Parameter->getIdentifier()->isPlaceholder()) {
15404 Diag(
Parameter->getLocation(), diag::warn_unused_parameter)
15412 if (LangOpts.NumLargeByValueCopy == 0)
15419 if (Size > LangOpts.NumLargeByValueCopy)
15430 if (Size > LangOpts.NumLargeByValueCopy)
15440 if (!getLangOpts().ObjCAutoRefCount ||
15450 if (!
T.isConstQualified()) {
15453 NameLoc, diag::err_arc_array_param_no_ownership,
T,
false));
15455 Diag(NameLoc, diag::err_arc_array_param_no_ownership)
15472 if (getLangOpts().ObjCAutoRefCount &&
15482 if (!
T.isConstQualified()) {
15486 NameLoc, diag::err_arc_array_param_no_ownership,
T,
false));
15488 Diag(NameLoc, diag::err_arc_array_param_no_ownership)
15500 TSInfo, SC,
nullptr);
15506 if (
auto *LSI = getEnclosingLambda())
15507 LSI->LocalPacks.push_back(New);
15512 NTCUC_FunctionParam, NTCUK_Destruct|NTCUK_Copy);
15520 diag::err_object_cannot_be_passed_returned_by_value) << 1 <<
T
15533 !(getLangOpts().
OpenCL &&
15539 Diag(NameLoc, diag::err_arg_with_address_space);
15567 for (
int i = FTI.
NumParams; i != 0; ) {
15570 if (getLangOpts().
C99) {
15572 llvm::raw_svector_ostream(Code)
15583 const char* PrevSpec;
15593 FTI.
Params[i].
Param = ActOnParamDeclarator(S, ParamD);
15603 assert(getCurFunctionDecl() ==
nullptr &&
"Function parsing confused");
15615 if (LangOpts.OpenMP && OpenMP().isInOpenMPDeclareVariantScope())
15616 OpenMP().ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
15617 ParentScope, D, TemplateParameterLists, Bases);
15620 Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists);
15621 Decl *Dcl = ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody, BodyKind);
15623 if (!Bases.empty())
15624 OpenMP().ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(Dcl,
15631 Consumer.HandleInlineFunctionDefinition(D);
15640 if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
15643 PossiblePrototype = Prev;
15661 if (isa<CXXMethodDecl>(FD))
15667 if (II->isStr(
"main") || II->isStr(
"efi_main"))
15683 if (FD->
hasAttr<OpenCLKernelAttr>())
15712 if (
FunctionDecl *OrigDef = Definition->getInstantiatedFromMemberFunction()) {
15729 if (TypoCorrectedFunctionDefinitions.count(Definition))
15734 if (SkipBody && !hasVisibleDefinition(Definition) &&
15736 Definition->isInlined() || Definition->getDescribedFunctionTemplate() ||
15737 Definition->getNumTemplateParameterLists())) {
15740 if (
auto *TD = Definition->getDescribedFunctionTemplate())
15741 makeMergedDefinitionVisible(TD);
15742 makeMergedDefinitionVisible(
const_cast<FunctionDecl*
>(Definition));
15746 if (getLangOpts().
GNUMode && Definition->isInlineSpecified() &&
15747 Definition->getStorageClass() ==
SC_Extern)
15749 << FD << getLangOpts().CPlusPlus;
15753 Diag(Definition->getLocation(), diag::note_previous_definition);
15762 LSI->
Lambda = LambdaClass;
15786 for (
const auto &C : LambdaClass->
captures()) {
15787 if (C.capturesVariable()) {
15790 CurrentInstantiationScope->InstantiatedLocal(VD, VD);
15791 const bool ByRef = C.getCaptureKind() ==
LCK_ByRef;
15793 true, C.getLocation(),
15794 C.isPackExpansion()
15796 I->getType(),
false);
15798 }
else if (C.capturesThis()) {
15816 PushFunctionScope();
15817 PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
15824 FD = FunTmpl->getTemplatedDecl();
15826 FD = cast<FunctionDecl>(D);
15835 PushExpressionEvaluationContext(
15836 FD->
isConsteval() ? ExpressionEvaluationContext::ImmediateFunctionContext
15837 : ExprEvalContexts.back().Context);
15846 ExprEvalContexts.back().InImmediateFunctionContext = FD->
isConsteval();
15847 ExprEvalContexts.back().InImmediateEscalatingFunctionContext =
15851 if (
const auto *
Attr = FD->
getAttr<AliasAttr>()) {
15856 if (
const auto *
Attr = FD->
getAttr<IFuncAttr>()) {
15861 if (
const auto *
Attr = FD->
getAttr<TargetVersionAttr>()) {
15863 !
Attr->isDefaultVersion()) {
15872 if (
auto *Ctor = dyn_cast<CXXConstructorDecl>(FD)) {
15874 Ctor->isDefaultConstructor() &&
15878 InstantiateDefaultCtorDefaultArgs(Ctor);
15886 CheckForFunctionRedefinition(FD,
nullptr, SkipBody);
15914 PushFunctionScope();
15916 assert(inTemplateInstantiation() &&
15917 "There should be an active template instantiation on the stack "
15918 "when instantiating a generic lambda!");
15919 RebuildLambdaScopeInfo(cast<CXXMethodDecl>(D));
15923 PushFunctionScope();
15943 (RequireCompleteType(FD->
getLocation(), ResultType,
15944 diag::err_func_def_incomplete_result) ||
15946 diag::err_abstract_type_in_decl,
15947 AbstractReturnType)))
15951 PushDeclContext(FnBodyScope, FD);
15962 auto *NonParmDecl = dyn_cast<NamedDecl>(NPD);
15965 assert(!isa<ParmVarDecl>(NonParmDecl) &&
15966 "parameters should not be in newly created FD yet");
15969 if (NonParmDecl->getDeclName())
15970 PushOnScopeChains(NonParmDecl, FnBodyScope,
false);
15974 if (
auto *ED = dyn_cast<EnumDecl>(NonParmDecl)) {
15975 for (
auto *EI : ED->enumerators())
15976 PushOnScopeChains(EI, FnBodyScope,
false);
15983 Param->setOwningFunction(FD);
15986 if (Param->getIdentifier() && FnBodyScope) {
15987 CheckShadow(FnBodyScope, Param);
15989 PushOnScopeChains(Param, FnBodyScope);
15998 if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
16015 assert(!FD->
hasAttr<DLLExportAttr>());
16016 Diag(FD->
getLocation(), diag::err_attribute_dllimport_function_definition);
16023 applyFunctionAttributesBeforeParsingBody(D);
16027 ActOnDocumentableDecl(D);
16028 if (getCurLexicalContext()->isObjCContainer() &&
16029 getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl &&
16030 getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation)
16039 if (
auto *TD = dyn_cast<FunctionTemplateDecl>(FD))
16040 FD = TD->getTemplatedDecl();
16041 if (FD && FD->
hasAttr<OptimizeNoneAttr>()) {
16044 CurFPFeatures.applyChanges(FPO);
16045 FpPragmaStack.CurrentValue =
16046 CurFPFeatures.getChangesFrom(
FPOptions(LangOpts));
16065 for (
unsigned I = 0, E =
Scope->Returns.size(); I != E; ++I) {
16066 if (
const VarDecl *NRVOCandidate = Returns[I]->getNRVOCandidate()) {
16067 if (!NRVOCandidate->isNRVOVariable())
16086 Outer.Fun.hasTrailingReturnType()) {
16087 QualType Ty = GetTypeFromParser(Outer.Fun.getTrailingReturnType());
16104 if (FD->isConstexpr())
16109 if (FD->getReturnType()->getContainedDeducedType())
16112 return Consumer.shouldSkipFunctionBody(D);
16119 FD->setHasSkippedBody();
16126 return ActOnFinishFunctionBody(D, BodyArg,
false);
16141 bool IsLambda =
false;
16145 llvm::DenseMap<const BlockDecl *, bool> EscapeInfo;
16147 auto IsOrNestedInEscapingBlock = [&](
const BlockDecl *BD) {
16148 if (EscapeInfo.count(BD))
16149 return EscapeInfo[BD];
16161 return EscapeInfo[BD] = R;
16166 for (
const std::pair<SourceLocation, const BlockDecl *> &
P :
16168 if (IsOrNestedInEscapingBlock(
P.second))
16169 S.
Diag(
P.first, diag::warn_implicitly_retains_self)
16174 return isa<CXXMethodDecl>(FD) && FD->
param_empty() &&
16184 methodHasName(FD,
"get_return_object_on_allocation_failure");
16192 if (CanBeGetReturnObject(FD) || CanBeGetReturnTypeOnAllocFailure(FD))
16194 if (!FD->
hasAttr<CoroWrapperAttr>())
16199 bool IsInstantiation) {
16204 FD->
addAttr(StrictFPAttr::CreateImplicit(Context));
16212 CheckCompletedCoroutineBody(FD, Body);
16214 CheckCoroutineWrapper(FD);
16235 CheckImmediateEscalatingFunctionDefinition(FD, FSI);
16249 Expr *Dummy =
nullptr;
16250 if (DeduceFunctionTypeFromReturnExpr(
16259 auto *LSI = getCurLambda();
16260 if (LSI->HasImplicitReturnType) {
16261 deduceClosureReturnType(*LSI);
16267 LSI->ReturnType.isNull() ? Context.
VoidTy : LSI->ReturnType;
16272 Proto->getExtProtoInfo()));
16293 DiagnoseSizeOfParametersAndReturnValue(FD->
parameters(),
16298 MarkVTableUsed(FD->
getLocation(), Constructor->getParent());
16300 dyn_cast<CXXDestructorDecl>(FD))
16301 MarkVTableUsed(FD->
getLocation(), Destructor->getParent());
16308 computeNRVO(Body, FSI);
16320 if (PossiblePrototype) {
16324 TypeLoc TL = TI->getTypeLoc();
16327 diag::note_declaration_not_a_prototype)
16330 FTL.getRParenLoc(),
"void")
16337 std::pair<FileID, unsigned> LocInfo =
SM.getDecomposedLoc(Loc);
16338 if (LocInfo.first.isInvalid())
16341 bool Invalid =
false;
16342 StringRef Buffer =
SM.getBufferData(LocInfo.first, &Invalid);
16346 if (LocInfo.second > Buffer.size())
16349 const char *LexStart = Buffer.data() + LocInfo.second;
16350 StringRef StartTok(LexStart, Buffer.size() - LocInfo.second);
16352 return StartTok.consume_front(
"const") &&
16354 StartTok.starts_with(
"/*") || StartTok.starts_with(
"//"));
16357 auto findBeginLoc = [&]() {
16365 if (isLocAtConst(FD->
getBeginLoc(), getSourceManager(),
16373 diag::note_static_for_internal_linkage)
16384 if (!PossiblePrototype)
16430 if (PossiblePrototype)
16432 diag::warn_non_prototype_changes_behavior)
16439 if (
const auto *CmpndBody = dyn_cast<CompoundStmt>(Body))
16440 if (!CmpndBody->body_empty())
16441 Diag(CmpndBody->body_front()->getBeginLoc(),
16442 diag::warn_dispatch_body_ignored);
16444 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
16459 if (KeyFunction && KeyFunction->
isDefined(Definition))
16460 MarkVTableUsed(Definition->getLocation(), MD->
getParent(),
true);
16468 assert((FD == getCurFunctionDecl(
true)) &&
16469 "Function parsing confused");
16470 }
else if (
ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
16471 assert(MD == getCurMethodDecl() &&
"Method parsing confused");
16474 DiagnoseSizeOfParametersAndReturnValue(MD->
parameters(),
16478 computeNRVO(Body, FSI);
16482 << MD->getSelector().getAsString();
16487 bool isDesignated =
16488 MD->isDesignatedInitializerForTheInterface(&InitMethod);
16489 assert(isDesignated && InitMethod);
16490 (void)isDesignated;
16493 auto IFace = MD->getClassInterface();
16496 auto SuperD = IFace->getSuperClass();
16506 diag::warn_objc_designated_init_missing_super_call);
16508 diag::note_objc_designated_init_marked_here);
16516 diag::warn_objc_secondary_init_missing_init_call);
16524 PopFunctionScopeInfo(ActivePolicy, dcl);
16529 DiagnoseUnguardedAvailabilityViolations(dcl);
16532 "This should only be set for ObjC methods, which should have been "
16533 "handled in the block above.");
16540 if (FD && isa<CXXConstructorDecl>(FD) && isa<CXXTryStmt>(Body))
16541 DiagnoseReturnInConstructorExceptionHandler(cast<CXXTryStmt>(Body));
16545 DiagnoseInvalidJumps(Body);
16548 if (!Destructor->getParent()->isDependentType())
16549 CheckDestructor(Destructor);
16551 MarkBaseAndMemberDestructorsReferenced(Destructor->getLocation(),
16552 Destructor->getParent());
16558 if (hasUncompilableErrorOccurred() ||
16559 hasAnyUnrecoverableErrorsInThisFunction() ||
16560 getDiagnostics().getSuppressAllDiagnostics()) {
16561 DiscardCleanupsInEvaluationContext();
16563 if (!hasUncompilableErrorOccurred() && !isa<FunctionTemplateDecl>(dcl)) {
16566 ActivePolicy = &WP;
16569 if (!IsInstantiation && FD &&
16572 !CheckConstexprFunctionDefinition(FD, CheckConstexprKind::Diagnose))
16575 if (FD && FD->
hasAttr<NakedAttr>()) {
16579 bool RegisterVariables =
false;
16580 if (
auto *DS = dyn_cast<DeclStmt>(S)) {
16581 for (
const auto *
Decl : DS->decls()) {
16582 if (
const auto *Var = dyn_cast<VarDecl>(
Decl)) {
16583 RegisterVariables =
16584 Var->hasAttr<AsmLabelAttr>() && !Var->hasInit();
16585 if (!RegisterVariables)
16590 if (RegisterVariables)
16592 if (!isa<AsmStmt>(S) && !isa<NullStmt>(S)) {
16593 Diag(S->getBeginLoc(), diag::err_non_asm_stmt_in_naked_function);
16594 Diag(FD->
getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
16601 assert(ExprCleanupObjects.size() ==
16602 ExprEvalContexts.back().NumCleanupObjects &&
16603 "Leftover temporaries in function");
16604 assert(!Cleanup.exprNeedsCleanups() &&
16605 "Unaccounted cleanups in function");
16606 assert(MaybeODRUseExprs.empty() &&
16607 "Leftover expressions for odr-use checking");
16613 if (!IsInstantiation)
16616 PopFunctionScopeInfo(ActivePolicy, dcl);
16620 if (hasUncompilableErrorOccurred()) {
16621 DiscardCleanupsInEvaluationContext();
16624 if (FD && ((LangOpts.OpenMP && (LangOpts.OpenMPIsTargetDevice ||
16626 LangOpts.CUDA || LangOpts.SYCLIsDevice)) {
16627 auto ES = getEmissionStatus(FD);
16630 DeclsToCheckForDeferredDiags.insert(FD);
16645 D = TD->getTemplatedDecl();
16646 ProcessDeclAttributeList(S, D, Attrs);
16649 if (
CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(D))
16650 if (Method->isStatic())
16651 checkThisInStaticMemberFunctionAttributes(Method);
16660 "Implicit function declarations aren't allowed in this language mode");
16667 Scope *BlockScope = S;
16675 Scope *ContextScope = BlockScope;
16679 ContextScope = ContextScope->
getParent();
16686 NamedDecl *ExternCPrev = findLocallyScopedExternCDecl(&II);
16690 PushOnScopeChains(ExternCPrev, BlockScope,
false);
16695 if (!isa<FunctionDecl>(ExternCPrev) ||
16697 cast<FunctionDecl>(ExternCPrev)->getType(),
16699 Diag(Loc, diag::ext_use_out_of_scope_declaration)
16700 << ExternCPrev << !getLangOpts().C99;
16702 return ExternCPrev;
16708 if (II.
getName().starts_with(
"__builtin_"))
16709 diag_id = diag::warn_builtin_unknown;
16711 else if (getLangOpts().
C99)
16712 diag_id = diag::ext_implicit_function_decl_c99;
16714 diag_id = diag::warn_implicit_function_decl;
16722 if (S && !ExternCPrev &&
16726 S,
nullptr, CCC, CTK_NonError);
16729 Diag(Loc, diag_id) << &II;
16733 bool Diagnose =
true;
16737 diagnoseTypo(Corrected, PDiag(diag::note_function_suggestion),
16745 return ExternCPrev;
16755 assert(!Error &&
"Error setting up implicit decl!");
16780 FunctionDecl *FD = cast<FunctionDecl>(ActOnDeclarator(BlockScope, D));
16783 AddKnownFunctionAttributes(FD);
16803 std::optional<unsigned> AlignmentParam;
16804 bool IsNothrow =
false;
16816 if (!IsNothrow && !FD->
hasAttr<ReturnsNonNullAttr>() &&
16817 !getLangOpts().CheckNew)
16834 if (!FD->
hasAttr<AllocSizeAttr>()) {
16835 FD->
addAttr(AllocSizeAttr::CreateImplicit(
16846 if (AlignmentParam && !FD->
hasAttr<AllocAlignAttr>()) {
16847 FD->
addAttr(AllocAlignAttr::CreateImplicit(
16880 unsigned FormatIdx;
16883 if (!FD->
hasAttr<FormatAttr>()) {
16884 const char *fmt =
"printf";
16886 if (FormatIdx < NumParams &&
16889 FD->
addAttr(FormatAttr::CreateImplicit(Context,
16892 HasVAListArg ? 0 : FormatIdx+2,
16898 if (!FD->
hasAttr<FormatAttr>())
16899 FD->
addAttr(FormatAttr::CreateImplicit(Context,
16902 HasVAListArg ? 0 : FormatIdx+2,
16908 if (!FD->
hasAttr<CallbackAttr>() &&
16910 FD->
addAttr(CallbackAttr::CreateImplicit(
16916 bool NoExceptions =
16918 bool ConstWithoutErrnoAndExceptions =
16920 bool ConstWithoutExceptions =
16922 if (!FD->
hasAttr<ConstAttr>() &&
16923 (ConstWithoutErrnoAndExceptions || ConstWithoutExceptions) &&
16924 (!ConstWithoutErrnoAndExceptions ||
16925 (!getLangOpts().MathErrno && NoExceptions)) &&
16926 (!ConstWithoutExceptions || NoExceptions))
16933 if ((Trip.isGNUEnvironment() || Trip.isOSMSVCRT()) &&
16935 switch (BuiltinID) {
16936 case Builtin::BI__builtin_fma:
16937 case Builtin::BI__builtin_fmaf:
16938 case Builtin::BI__builtin_fmal:
16939 case Builtin::BIfma:
16940 case Builtin::BIfmaf:
16941 case Builtin::BIfmal:
16950 !FD->
hasAttr<ReturnsTwiceAttr>())
16951 FD->
addAttr(ReturnsTwiceAttr::CreateImplicit(Context,
16960 !FD->
hasAttr<CUDADeviceAttr>() && !FD->
hasAttr<CUDAHostAttr>()) {
16964 if (((getLangOpts().SYCLIsDevice && getLangOpts().
CUDA &&
16965 !getLangOpts().CUDAIsDevice) ||
16966 getLangOpts().CUDAIsDevice) !=
16974 switch (BuiltinID) {
16975 case Builtin::BImemalign:
16976 case Builtin::BIaligned_alloc:
16977 if (!FD->
hasAttr<AllocAlignAttr>())
16986 switch (BuiltinID) {
16987 case Builtin::BIcalloc:
16988 FD->
addAttr(AllocSizeAttr::CreateImplicit(
16991 case Builtin::BImemalign:
16992 case Builtin::BIaligned_alloc:
16993 case Builtin::BIrealloc:
16997 case Builtin::BImalloc:
17006 switch (BuiltinID) {
17007 case Builtin::BIaddressof:
17008 case Builtin::BI__addressof:
17009 case Builtin::BI__builtin_addressof:
17010 case Builtin::BIas_const:
17011 case Builtin::BIforward:
17012 case Builtin::BIforward_like:
17013 case Builtin::BImove:
17014 case Builtin::BImove_if_noexcept:
17016 !
P->hasAttr<LifetimeBoundAttr>())
17018 LifetimeBoundAttr::CreateImplicit(Context, FD->
getLocation()));
17025 AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);
17030 if (getLangOpts().CXXExceptions && getLangOpts().ExternCNoUnwind &&
17033 if (!FPT || FPT->getExceptionSpecType() ==
EST_None)
17049 if (Name->isStr(
"asprintf") || Name->isStr(
"vasprintf")) {
17052 if (!FD->
hasAttr<FormatAttr>())
17053 FD->
addAttr(FormatAttr::CreateImplicit(Context,
17055 Name->isStr(
"vasprintf") ? 0 : 3,
17059 if (Name->isStr(
"__CFStringMakeConstantString")) {
17062 if (!FD->
hasAttr<FormatArgAttr>())
17070 assert(D.
getIdentifier() &&
"Wrong callback for declspec without declarator");
17071 assert(!
T.isNull() &&
"GetTypeForDeclarator() returned null type");
17074 assert(D.
isInvalidType() &&
"no declarator info for valid type");
17090 if (CurContext->isFunctionOrMethod())
17113 setTagNameForLinkagePurposes(tagFromDeclSpec, NewTD);
17135 if (BT->isInteger())
17138 return Diag(UnderlyingLoc, diag::err_enum_invalid_underlying)
17145 QualType EnumUnderlyingTy,
bool IsFixed,
17147 if (IsScoped != Prev->
isScoped()) {
17148 Diag(EnumLoc, diag::err_enum_redeclare_scoped_mismatch)
17154 if (IsFixed && Prev->
isFixed()) {
17160 Diag(EnumLoc, diag::err_enum_redeclare_type_mismatch)
17166 }
else if (IsFixed != Prev->
isFixed()) {
17167 Diag(EnumLoc, diag::err_enum_redeclare_fixed_mismatch)
17189 default: llvm_unreachable(
"Invalid tag kind for redecl diagnostic!");
17205 if (isa<TypedefDecl>(PrevDecl))
17206 return NTK_Typedef;
17207 else if (isa<TypeAliasDecl>(PrevDecl))
17208 return NTK_TypeAlias;
17209 else if (isa<ClassTemplateDecl>(PrevDecl))
17210 return NTK_Template;
17211 else if (isa<TypeAliasTemplateDecl>(PrevDecl))
17212 return NTK_TypeAliasTemplate;
17213 else if (isa<TemplateTemplateParmDecl>(PrevDecl))
17214 return NTK_TemplateTemplateArgument;
17219 return getLangOpts().CPlusPlus ? NTK_NonClass : NTK_NonStruct;
17221 return NTK_NonUnion;
17223 return NTK_NonEnum;
17225 llvm_unreachable(
"invalid TTK");
17250 if (OldTag != NewTag &&
17265 return getDiagnostics().isIgnored(diag::warn_struct_class_tag_mismatch,
17268 if (IsIgnoredLoc(NewTagLoc))
17271 auto IsIgnored = [&](
const TagDecl *Tag) {
17272 return IsIgnoredLoc(Tag->getLocation());
17285 if (inTemplateInstantiation()) {
17286 if (OldTag != NewTag) {
17289 Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
17297 if (isDefinition) {
17305 bool previousMismatch =
false;
17307 if (I->getTagKind() != NewTag) {
17312 if (!previousMismatch) {
17313 previousMismatch =
true;
17314 Diag(NewTagLoc, diag::warn_struct_class_previous_tag_mismatch)
17318 Diag(I->getInnerLocStart(), diag::note_struct_class_suggestion)
17331 if (PrevDef && IsIgnored(PrevDef))
17335 Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
17342 Diag(NewTagLoc, diag::note_struct_class_suggestion)
17372 if (!Namespace || Namespace->isAnonymousNamespace())
17375 Namespaces.push_back(II);
17378 if (Lookup == Namespace)
17385 llvm::raw_svector_ostream OS(Insertion);
17388 std::reverse(Namespaces.begin(), Namespaces.end());
17389 for (
auto *II : Namespaces)
17390 OS << II->getName() <<
"::";
17403 if (OldDC->
Equals(NewDC))
17432 bool ScopedEnumUsesClassTag,
TypeResult UnderlyingType,
17433 bool IsTypeSpecifier,
bool IsTemplateParamOrArg,
17437 assert((Name !=
nullptr || TUK == TUK_Definition) &&
17438 "Nameless record must be a definition!");
17439 assert(TemplateParameterLists.size() == 0 || TUK != TUK_Reference);
17443 bool ScopedEnum = ScopedEnumKWLoc.
isValid();
17446 bool isMemberSpecialization =
false;
17447 bool Invalid =
false;
17452 if (TemplateParameterLists.size() > 0 ||
17453 (SS.
isNotEmpty() && TUK != TUK_Reference)) {
17455 MatchTemplateParametersToScopeSpecifier(
17456 KWLoc, NameLoc, SS,
nullptr, TemplateParameterLists,
17457 TUK == TUK_Friend, isMemberSpecialization, Invalid);
17472 if (TUK == TUK_Declaration && SS.
isNotEmpty() && !isMemberSpecialization)
17473 Diag(SS.
getBeginLoc(), diag::err_standalone_class_nested_name_specifier)
17476 if (TemplateParams) {
17478 Diag(KWLoc, diag::err_enum_template);
17482 if (TemplateParams->
size() > 0) {
17491 S, TagSpec, TUK, KWLoc, SS, Name, NameLoc, Attrs, TemplateParams,
17492 AS, ModulePrivateLoc,
17494 TemplateParameterLists.data(), SkipBody);
17495 return Result.get();
17500 isMemberSpecialization =
true;
17504 if (!TemplateParameterLists.empty() && isMemberSpecialization &&
17505 CheckTemplateDeclScope(S, TemplateParameterLists.back()))
17523 ScopedEnum ?
SourceRange(KWLoc, ScopedEnumKWLoc) : KWLoc);
17524 assert(ScopedEnum || !ScopedEnumUsesClassTag);
17525 Diag(KWLoc, diag::note_enum_friend)
17526 << (ScopedEnum + ScopedEnumUsesClassTag);
17532 llvm::PointerUnion<const Type*, TypeSourceInfo*> EnumUnderlying;
17533 bool IsFixed = !UnderlyingType.
isUnset() || ScopedEnum;
17536 if (UnderlyingType.
isInvalid() || (!UnderlyingType.
get() && ScopedEnum)) {
17540 }
else if (UnderlyingType.
get()) {
17544 GetTypeFromParser(UnderlyingType.
get(), &TI);
17545 EnumUnderlying = TI;
17547 if (CheckEnumUnderlyingType(TI))
17552 UPPC_FixedUnderlyingType))
17560 if (TUK == TUK_Definition || getLangOpts().MSVCCompat)
17567 bool isStdBadAlloc =
false;
17568 bool isStdAlignValT =
false;
17571 if (TUK == TUK_Friend || TUK == TUK_Reference)
17577 auto createTagFromNewDecl = [&]() ->
TagDecl * {
17578 assert(!getLangOpts().
CPlusPlus &&
"not meant for C++ usage");
17587 ScopedEnum, ScopedEnumUsesClassTag, IsFixed);
17589 if (TUK != TUK_Definition && !Invalid)
17591 if (EnumUnderlying) {
17592 EnumDecl *ED = cast<EnumDecl>(New);
17607 if (
RecordDecl *RD = dyn_cast<RecordDecl>(New)) {
17617 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip)) {
17618 AddAlignmentAttributesForRecord(RD);
17619 AddMsStructLayoutForRecord(RD);
17633 goto CreateNewDecl;
17638 if (TUK == TUK_Friend || TUK == TUK_Reference) {
17639 DC = computeDeclContext(SS,
false);
17641 IsDependent =
true;
17645 DC = computeDeclContext(SS,
true);
17653 if (RequireCompleteDeclContext(SS, DC))
17658 LookupQualifiedName(
Previous, DC);
17670 if (
Previous.wasNotFoundInCurrentInstantiation() &&
17671 (TUK == TUK_Reference || TUK == TUK_Friend)) {
17672 IsDependent =
true;
17677 Diag(NameLoc, diag::err_not_tag_in_scope)
17678 << llvm::to_underlying(
Kind) << Name << DC << SS.
getRange();
17681 goto CreateNewDecl;
17688 if (TUK != TUK_Reference && TUK != TUK_Friend &&
17702 (TUK == TUK_Definition || TUK == TUK_Declaration)) {
17726 if (!
Previous.empty() && TUK == TUK_Friend) {
17729 bool FriendSawTagOutsideEnclosingNamespace =
false;
17735 if (getLangOpts().MSVCCompat)
17736 FriendSawTagOutsideEnclosingNamespace =
true;
17745 if (
Previous.isSingleResult() && FriendSawTagOutsideEnclosingNamespace) {
17747 Diag(NameLoc, diag::ext_friend_tag_redecl_outside_namespace)
17756 if (!getLangOpts().
CPlusPlus && TUK != TUK_Reference) {
17761 while (isa<RecordDecl, EnumDecl, ObjCContainerDecl>(SearchDC))
17767 while (isa<ObjCContainerDecl>(SearchDC))
17773 while (isa<ObjCContainerDecl>(SearchDC))
17778 Previous.getFoundDecl()->isTemplateParameter()) {
17780 DiagnoseTemplateParameterShadow(NameLoc,
Previous.getFoundDecl());
17785 if (getLangOpts().
CPlusPlus && Name && DC && StdNamespace &&
17786 DC->
Equals(getStdNamespace())) {
17787 if (Name->isStr(
"bad_alloc")) {
17789 isStdBadAlloc =
true;
17794 if (
Previous.empty() && StdBadAlloc)
17795 Previous.addDecl(getStdBadAlloc());
17796 }
else if (Name->isStr(
"align_val_t")) {
17797 isStdAlignValT =
true;
17798 if (
Previous.empty() && StdAlignValT)
17799 Previous.addDecl(getStdAlignValT());
17808 (TUK == TUK_Reference || TUK == TUK_Friend || IsTemplateParamOrArg)) {
17809 if (Invalid)
goto CreateNewDecl;
17812 if (TUK == TUK_Reference || IsTemplateParamOrArg) {
17846 assert(TUK == TUK_Friend);
17866 Previous.setRedeclarationKind(forRedeclarationInCurContext());
17867 LookupQualifiedName(
Previous, SearchDC);
17869 Previous.setRedeclarationKind(forRedeclarationInCurContext());
17893 TagDecl *Tag = TT->getDecl();
17896 ->
Equals(TD->getDeclContext()->getRedeclContext())) {
17909 if (
auto *Shadow = dyn_cast<UsingShadowDecl>(DirectPrevDecl)) {
17910 auto *OldTag = dyn_cast<TagDecl>(PrevDecl);
17911 if (SS.
isEmpty() && TUK != TUK_Reference && TUK != TUK_Friend &&
17912 isDeclInScope(Shadow, SearchDC, S, isMemberSpecialization) &&
17914 *
this, OldTag->getDeclContext(), SearchDC))) {
17915 Diag(KWLoc, diag::err_using_decl_conflict_reverse);
17916 Diag(Shadow->getTargetDecl()->getLocation(),
17917 diag::note_using_decl_target);
17918 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
17922 goto CreateNewDecl;
17926 if (
TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) {
17930 if (TUK == TUK_Reference || TUK == TUK_Friend ||
17931 isDeclInScope(DirectPrevDecl, SearchDC, S,
17932 SS.
isNotEmpty() || isMemberSpecialization)) {
17935 if (!isAcceptableTagRedeclaration(PrevTagDecl,
Kind,
17936 TUK == TUK_Definition, KWLoc,
17938 bool SafeToContinue =
17941 if (SafeToContinue)
17942 Diag(KWLoc, diag::err_use_with_wrong_tag)
17945 PrevTagDecl->getKindName());
17947 Diag(KWLoc, diag::err_use_with_wrong_tag) << Name;
17948 Diag(PrevTagDecl->getLocation(), diag::note_previous_use);
17950 if (SafeToContinue)
17951 Kind = PrevTagDecl->getTagKind();
17962 const EnumDecl *PrevEnum = cast<EnumDecl>(PrevTagDecl);
17963 if (TUK == TUK_Reference || TUK == TUK_Friend)
17964 return PrevTagDecl;
17968 EnumUnderlyingTy = TI->getType().getUnqualifiedType();
17969 else if (
const Type *
T = EnumUnderlying.dyn_cast<
const Type*>())
17975 if (CheckEnumRedeclaration(NameLoc.
isValid() ? NameLoc : KWLoc,
17976 ScopedEnum, EnumUnderlyingTy,
17977 IsFixed, PrevEnum))
17978 return TUK == TUK_Declaration ? PrevTagDecl :
nullptr;
17986 S->isDeclScope(PrevDecl)) {
17987 Diag(NameLoc, diag::ext_member_redeclared);
17988 Diag(PrevTagDecl->getLocation(), diag::note_previous_declaration);
17994 if (TUK == TUK_Reference || TUK == TUK_Friend) {
17995 if (!Attrs.
empty()) {
17998 }
else if (TUK == TUK_Reference &&
17999 (PrevTagDecl->getFriendObjectKind() ==
18012 return PrevTagDecl;
18017 return PrevTagDecl;
18022 if (TUK == TUK_Definition) {
18023 if (
NamedDecl *Def = PrevTagDecl->getDefinition()) {
18027 bool IsExplicitSpecializationAfterInstantiation =
false;
18028 if (isMemberSpecialization) {
18030 IsExplicitSpecializationAfterInstantiation =
18031 RD->getTemplateSpecializationKind() !=
18033 else if (
EnumDecl *ED = dyn_cast<EnumDecl>(Def))
18034 IsExplicitSpecializationAfterInstantiation =
18035 ED->getTemplateSpecializationKind() !=
18044 if (SkipBody && !hasVisibleDefinition(Def, &Hidden)) {
18055 SkipBody->
New = createTagFromNewDecl();
18061 makeMergedDefinitionVisible(Hidden);
18065 }
else if (!IsExplicitSpecializationAfterInstantiation) {
18068 if (!getLangOpts().
CPlusPlus && S->containedInPrototypeScope())
18069 Diag(NameLoc, diag::warn_redefinition_in_param_list) << Name;
18071 Diag(NameLoc, diag::err_redefinition) << Name;
18072 notePreviousDefinition(Def,
18073 NameLoc.
isValid() ? NameLoc : KWLoc);
18085 if (TD->isBeingDefined()) {
18086 Diag(NameLoc, diag::err_nested_redefinition) << Name;
18087 Diag(PrevTagDecl->getLocation(),
18088 diag::note_previous_definition);
18102 if (TUK == TUK_Friend || TUK == TUK_Reference) {
18103 SearchDC = PrevTagDecl->getDeclContext();
18128 if ((TUK == TUK_Reference || TUK == TUK_Friend) &&
18131 Diag(NameLoc, diag::err_tag_reference_non_tag)
18132 << PrevDecl << NTK << llvm::to_underlying(
Kind);
18137 }
else if (!isDeclInScope(DirectPrevDecl, SearchDC, S,
18138 SS.
isNotEmpty() || isMemberSpecialization)) {
18142 }
else if (TUK == TUK_Reference || TUK == TUK_Friend) {
18144 Diag(NameLoc, diag::err_tag_reference_conflict) << NTK;
18150 }
else if (
TypedefNameDecl *TND = dyn_cast<TypedefNameDecl>(PrevDecl)) {
18152 if (isa<TypeAliasDecl>(PrevDecl))
Kind = 1;
18153 Diag(NameLoc, diag::err_tag_definition_of_typedef)
18154 << Name <<
Kind << TND->getUnderlyingType();
18162 Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
18163 notePreviousDefinition(PrevDecl, NameLoc);
18178 PrevDecl = cast<TagDecl>(
Previous.getFoundDecl());
18194 cast_or_null<EnumDecl>(PrevDecl), ScopedEnum,
18195 ScopedEnumUsesClassTag, IsFixed);
18197 if (isStdAlignValT && (!StdAlignValT || getStdAlignValT()->isImplicit()))
18198 StdAlignValT = cast<EnumDecl>(New);
18201 if (TUK != TUK_Definition && !Invalid) {
18203 if (IsFixed && cast<EnumDecl>(New)->isFixed()) {
18207 else if (PrevDecl && (Def = cast<EnumDecl>(PrevDecl)->
getDefinition())) {
18208 Diag(Loc, diag::ext_forward_ref_enum_def)
18212 unsigned DiagID = diag::ext_forward_ref_enum;
18213 if (getLangOpts().MSVCCompat)
18214 DiagID = diag::ext_ms_forward_ref_enum;
18216 DiagID = diag::err_forward_ref_enum;
18221 if (EnumUnderlying) {
18222 EnumDecl *ED = cast<EnumDecl>(New);
18231 assert(ED->
isComplete() &&
"enum with type should be complete");
18241 cast_or_null<CXXRecordDecl>(PrevDecl));
18243 if (isStdBadAlloc && (!StdBadAlloc || getStdBadAlloc()->isImplicit()))
18244 StdBadAlloc = cast<CXXRecordDecl>(New);
18247 cast_or_null<RecordDecl>(PrevDecl));
18251 if (OOK != OOK_Outside && TUK == TUK_Definition && !getLangOpts().
CPlusPlus &&
18252 !getLangOpts().
C23)
18258 if (!Invalid && getLangOpts().CPlusPlus &&
18259 (IsTypeSpecifier || IsTemplateParamOrArg) && TUK == TUK_Definition) {
18265 if (!Invalid && getLangOpts().
CPlusPlus && TUK == TUK_Definition &&
18277 if ((TUK == TUK_Definition || TUK == TUK_Declaration) &&
18278 diagnoseQualifiedDeclaration(SS, DC, OrigName, Loc,
18280 isMemberSpecialization))
18284 if (TemplateParameterLists.size() > 0) {
18292 if (
RecordDecl *RD = dyn_cast<RecordDecl>(New)) {
18302 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip)) {
18303 AddAlignmentAttributesForRecord(RD);
18304 AddMsStructLayoutForRecord(RD);
18308 if (ModulePrivateLoc.
isValid()) {
18309 if (isMemberSpecialization)
18322 if (isMemberSpecialization && CheckMemberSpecialization(New,
Previous))
18329 getNonFieldDeclScope(S)->isFunctionPrototypeScope()) {
18333 if (TUK == TUK_Definition && !IsTypeSpecifier) {
18334 Diag(Loc, diag::err_type_defined_in_param_type)
18338 }
else if (!PrevDecl) {
18354 if (TUK == TUK_Friend)
18358 if (!Invalid && SearchDC->
isRecord())
18359 SetMemberAccessSpecifier(New, PrevDecl, AS);
18362 CheckRedeclarationInModule(New, PrevDecl);
18364 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip))
18367 ProcessDeclAttributeList(S, New, Attrs);
18368 AddPragmaAttributes(S, New);
18371 if (TUK == TUK_Friend) {
18380 if (
Scope *EnclosingScope = getScopeForDeclContext(S, DC))
18381 PushOnScopeChains(New, EnclosingScope,
false);
18383 S = getNonFieldDeclScope(S);
18384 PushOnScopeChains(New, S,
true);
18386 CurContext->addDecl(New);
18397 mergeDeclAttributes(New, PrevDecl);
18399 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(New)) {
18400 inferGslOwnerPointerAttribute(CXXRD);
18401 inferNullableClassAttribute(CXXRD);
18406 AddPushedVisibilityAttribute(New);
18409 CompleteMemberSpecialization(New,
Previous);
18414 if (Invalid && getLangOpts().
CPlusPlus) {
18416 if (
auto RD = dyn_cast<RecordDecl>(New))
18419 }
else if (SkipBody && SkipBody->
ShouldSkip) {
18427 AdjustDeclIfTemplate(TagD);
18428 TagDecl *Tag = cast<TagDecl>(TagD);
18431 PushDeclContext(S, Tag);
18433 ActOnDocumentableDecl(TagD);
18437 AddPushedVisibilityAttribute(Tag);
18441 if (!hasStructuralCompatLayout(Prev, SkipBody.
New))
18445 makeMergedDefinitionVisible(SkipBody.
Previous);
18451 "The next DeclContext should be lexically contained in the current one.");
18452 CurContext = IDecl;
18457 bool IsFinalSpelledSealed,
18460 AdjustDeclIfTemplate(TagD);
18463 FieldCollector->StartClass();
18465 if (!
Record->getIdentifier())
18472 Record->addAttr(FinalAttr::Create(Context, FinalLoc,
18473 IsFinalSpelledSealed
18474 ? FinalAttr::Keyword_sealed
18475 : FinalAttr::Keyword_final));
18483 Context,
Record->getTagKind(), CurContext,
Record->getBeginLoc(),
18492 PushOnScopeChains(InjectedClassName, S);
18494 "Broken injected-class-name");
18499 AdjustDeclIfTemplate(TagD);
18500 TagDecl *Tag = cast<TagDecl>(TagD);
18505 assert(Tag->
isInvalidDecl() &&
"We should already have completed it");
18506 if (
RecordDecl *RD = dyn_cast<RecordDecl>(Tag))
18510 if (
auto *RD = dyn_cast<CXXRecordDecl>(Tag)) {
18511 FieldCollector->FinishClass();
18512 if (RD->
hasAttr<SYCLSpecialClassAttr>() && getLangOpts().SYCLIsDevice) {
18514 assert(Def &&
"The record is expected to have a completed definition");
18515 unsigned NumInitMethods = 0;
18516 for (
auto *Method : Def->methods()) {
18517 if (!Method->getIdentifier())
18519 if (Method->getName() ==
"__init")
18522 if (NumInitMethods > 1 || !Def->hasInitMethod())
18523 Diag(RD->
getLocation(), diag::err_sycl_special_type_num_init_method);
18530 if (getCurLexicalContext()->isObjCContainer() &&
18536 Consumer.HandleTagDeclDefinition(Tag);
18541 AlignPackStack.hasValue()) {
18546 const RecordDecl *RD = dyn_cast<RecordDecl>(Tag);
18550 if (llvm::any_of(RD->
fields(),
18551 [](
const FieldDecl *FD) { return FD->isBitField(); }))
18552 Diag(BraceRange.
getBegin(), diag::warn_pragma_align_not_xl_compatible);
18562 assert(ObjCCtx == CurContext &&
"Mismatch of container contexts");
18563 OriginalLexicalContext = ObjCCtx;
18564 ActOnObjCContainerFinishDefinition();
18568 ActOnObjCContainerStartDefinition(ObjCCtx);
18569 OriginalLexicalContext =
nullptr;
18573 AdjustDeclIfTemplate(TagD);
18574 TagDecl *Tag = cast<TagDecl>(TagD);
18579 if (
RecordDecl *RD = dyn_cast<RecordDecl>(Tag))
18593 QualType FieldTy,
bool IsMsStruct,
18603 if (RequireCompleteSizedType(FieldLoc, FieldTy,
18604 diag::err_field_incomplete_or_sizeless))
18607 return Diag(FieldLoc, diag::err_not_integral_type_bitfield)
18609 return Diag(FieldLoc, diag::err_not_integral_type_anon_bitfield)
18611 }
else if (DiagnoseUnexpandedParameterPack(
const_cast<Expr *
>(BitWidth),
18612 UPPC_BitFieldWidth))
18621 ExprResult ICE = VerifyIntegerConstantExpression(BitWidth, &
Value, AllowFold);
18624 BitWidth = ICE.
get();
18627 if (
Value == 0 && FieldName)
18628 return Diag(FieldLoc, diag::err_bitfield_has_zero_width)
18631 if (
Value.isSigned() &&
Value.isNegative()) {
18633 return Diag(FieldLoc, diag::err_bitfield_has_negative_width)
18635 return Diag(FieldLoc, diag::err_anon_bitfield_has_negative_width)
18642 return Diag(FieldLoc, diag::err_bitfield_too_wide)
18649 bool BitfieldIsOverwide =
Value.ugt(TypeWidth);
18653 bool CStdConstraintViolation =
18654 BitfieldIsOverwide && !getLangOpts().CPlusPlus;
18655 bool MSBitfieldViolation =
18656 Value.ugt(TypeStorageSize) &&
18658 if (CStdConstraintViolation || MSBitfieldViolation) {
18659 unsigned DiagWidth =
18660 CStdConstraintViolation ? TypeWidth : TypeStorageSize;
18661 return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
18663 << !CStdConstraintViolation << DiagWidth;
18669 if (BitfieldIsOverwide && !FieldTy->
isBooleanType() && FieldName) {
18670 Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)
18683 FieldDecl *Res = HandleField(S, cast_if_present<RecordDecl>(TagD), DeclStart,
18710 CheckExtraCXXDefaultArguments(D);
18713 UPPC_DataMemberType)) {
18724 << getLangOpts().CPlusPlus17;
18727 diag::err_invalid_thread)
18735 switch (
Previous.getResultKind()) {
18742 PrevDecl =
Previous.getRepresentativeDecl();
18756 PrevDecl =
nullptr;
18759 if (PrevDecl && !isDeclInScope(PrevDecl,
Record, S))
18760 PrevDecl =
nullptr;
18766 = CheckFieldDecl(II,
T, TInfo,
Record, Loc, Mutable, BitWidth, InitStyle,
18767 TSSL, AS, PrevDecl, &D);
18770 Record->setInvalidDecl();
18779 PushOnScopeChains(NewFD, S);
18799 bool Mutable,
Expr *BitWidth,
18805 bool InvalidDecl =
false;
18811 InvalidDecl =
true;
18817 if (RequireCompleteSizedType(Loc, EltTy,
18818 diag::err_field_incomplete_or_sizeless)) {
18820 Record->setInvalidDecl();
18821 InvalidDecl =
true;
18826 Record->setInvalidDecl();
18827 InvalidDecl =
true;
18835 Diag(Loc, diag::err_field_with_address_space);
18836 Record->setInvalidDecl();
18837 InvalidDecl =
true;
18840 if (LangOpts.OpenCL) {
18845 Diag(Loc, diag::err_opencl_type_struct_or_union_field) <<
T;
18846 Record->setInvalidDecl();
18847 InvalidDecl =
true;
18851 if (BitWidth && !getOpenCLOptions().isAvailableOption(
18852 "__cl_clang_bitfields", LangOpts)) {
18853 Diag(Loc, diag::err_opencl_bitfields);
18854 InvalidDecl =
true;
18859 if (!InvalidDecl && getLangOpts().
CPlusPlus && !II && BitWidth &&
18860 T.hasQualifiers()) {
18861 InvalidDecl =
true;
18862 Diag(Loc, diag::err_anon_bitfield_qualifiers);
18868 if (!tryToFixVariablyModifiedVarType(
18869 TInfo,
T, Loc, diag::err_typecheck_field_variable_size))
18870 InvalidDecl =
true;
18874 if (!InvalidDecl && RequireNonAbstractType(Loc,
T,
18875 diag::err_abstract_type_in_decl,
18876 AbstractFieldType))
18877 InvalidDecl =
true;
18880 BitWidth =
nullptr;
18884 VerifyBitField(Loc, II,
T,
Record->isMsStruct(Context), BitWidth).get();
18886 InvalidDecl =
true;
18887 BitWidth =
nullptr;
18892 if (!InvalidDecl && Mutable) {
18893 unsigned DiagID = 0;
18895 DiagID = getLangOpts().MSVCCompat ? diag::ext_mutable_reference
18896 : diag::err_mutable_reference;
18897 else if (
T.isConstQualified())
18898 DiagID = diag::err_mutable_const;
18904 Diag(ErrLoc, DiagID);
18905 if (DiagID != diag::ext_mutable_reference) {
18907 InvalidDecl =
true;
18919 BitWidth, Mutable, InitStyle);
18923 if (PrevDecl && !isa<TagDecl>(PrevDecl) &&
18925 Diag(Loc, diag::err_duplicate_member) << II;
18930 if (!InvalidDecl && getLangOpts().
CPlusPlus) {
18931 if (
Record->isUnion()) {
18940 if (CheckNontrivialField(NewFD))
18950 diag::ext_union_member_of_reference_type :
18951 diag::err_union_member_of_reference_type)
18953 if (!getLangOpts().MicrosoftExt)
18963 ProcessDeclAttributes(getCurScope(), NewFD, *D);
18966 CheckAlignasUnderalignment(NewFD);
18971 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewFD))
18974 if (
T.isObjCGCWeak())
18975 Diag(Loc, diag::warn_attribute_weak_on_field);
18988 assert(getLangOpts().
CPlusPlus &&
"valid check only for C++");
19025 if (getSourceManager().isInSystemHeader(Loc)) {
19026 if (!FD->
hasAttr<UnavailableAttr>())
19027 FD->
addAttr(UnavailableAttr::CreateImplicit(Context,
"",
19028 UnavailableAttr::IR_ARCFieldWithOwnership, Loc));
19036 ? diag::warn_cxx98_compat_nontrivial_union_or_anon_struct_member
19037 : diag::err_illegal_union_or_anon_struct_member)
19039 << llvm::to_underlying(
member);
19040 DiagnoseNontrivial(RDecl,
member);
19041 return !getLangOpts().CPlusPlus11;
19053 switch (ivarVisibility) {
19054 default: llvm_unreachable(
"Unknown visitibility kind");
19079 BitWidth = VerifyBitField(Loc, II,
T,
false, BitWidth).get();
19089 Diag(Loc, diag::err_ivar_reference_type);
19095 if (!tryToFixVariablyModifiedVarType(
19096 TInfo,
T, Loc, diag::err_typecheck_ivar_variable_size))
19110 dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
19113 EnclosingContext = IMPDecl->getClassInterface();
19114 assert(EnclosingContext &&
"Implementation has no class interface!");
19117 EnclosingContext = EnclosingDecl;
19120 dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
19122 Diag(Loc, diag::err_misplaced_ivar) << CDecl->IsClassExtension();
19126 EnclosingContext = EnclosingDecl;
19131 Context, EnclosingContext, DeclStart, Loc, II,
T, TInfo, ac, BitWidth);
19138 LookupSingleName(S, II, Loc, LookupMemberName,
19140 if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S)
19141 && !isa<TagDecl>(PrevDecl)) {
19142 Diag(Loc, diag::err_duplicate_member) << II;
19149 ProcessDeclAttributes(S, NewID, D);
19155 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewID))
19165 IdResolver.AddDecl(NewID);
19169 !NewID->
isInvalidDecl() && isa<ObjCInterfaceDecl>(EnclosingDecl))
19170 Diag(Loc, diag::warn_ivars_in_interface);
19184 Decl *ivarDecl = AllIvarDecls[AllIvarDecls.size()-1];
19192 if (!CD->IsClassExtension())
19204 DeclLoc, DeclLoc,
nullptr,
19210 AllIvarDecls.push_back(Ivar);
19222 if (!
Record->hasUserDeclaredDestructor()) {
19230 if (
auto *DD = dyn_cast<CXXDestructorDecl>(
Decl)) {
19231 if (DD->isInvalidDecl())
19235 assert(DD->isIneligibleOrNotSelected() &&
"Selecting a destructor but a destructor was already selected.");
19249 Record->addedSelectedDestructor(dyn_cast<CXXDestructorDecl>(Best->Function));
19253 Msg = diag::err_ambiguous_destructor;
19258 Msg = diag::err_no_viable_destructor;
19269 Record->setInvalidDecl();
19276 Record->addedSelectedDestructor(dyn_cast<CXXDestructorDecl>(OCS.
begin()->Function));
19320 const Expr *Constraints = Method->getTrailingRequiresClause();
19322 SatisfactionStatus.push_back(
true);
19326 SatisfactionStatus.push_back(
false);
19328 SatisfactionStatus.push_back(Satisfaction.
IsSatisfied);
19332 for (
size_t i = 0; i < Methods.size(); i++) {
19333 if (!SatisfactionStatus[i])
19338 OrigMethod = cast<CXXMethodDecl>(MF);
19341 bool AnotherMethodIsMoreConstrained =
false;
19342 for (
size_t j = 0; j < Methods.size(); j++) {
19343 if (i == j || !SatisfactionStatus[j])
19347 OtherMethod = cast<CXXMethodDecl>(MF);
19354 if (!OtherConstraints)
19356 if (!Constraints) {
19357 AnotherMethodIsMoreConstrained =
true;
19362 AnotherMethodIsMoreConstrained)) {
19365 AnotherMethodIsMoreConstrained =
true;
19367 if (AnotherMethodIsMoreConstrained)
19372 if (!AnotherMethodIsMoreConstrained) {
19374 Record->addedEligibleSpecialMemberFunction(Method,
19375 1 << llvm::to_underlying(CSM));
19389 auto *MD = dyn_cast<CXXMethodDecl>(
Decl);
19391 auto *FTD = dyn_cast<FunctionTemplateDecl>(
Decl);
19393 MD = dyn_cast<CXXMethodDecl>(FTD->getTemplatedDecl());
19397 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
19398 if (CD->isInvalidDecl())
19400 if (CD->isDefaultConstructor())
19401 DefaultConstructors.push_back(MD);
19402 else if (CD->isCopyConstructor())
19403 CopyConstructors.push_back(MD);
19404 else if (CD->isMoveConstructor())
19405 MoveConstructors.push_back(MD);
19407 CopyAssignmentOperators.push_back(MD);
19409 MoveAssignmentOperators.push_back(MD);
19429 assert(EnclosingDecl &&
"missing record or interface decl");
19434 if (!Fields.empty() && isa<ObjCContainerDecl>(EnclosingDecl)) {
19438 case Decl::ObjCCategory:
19439 Context.
ResetObjCLayout(cast<ObjCCategoryDecl>(DC)->getClassInterface());
19441 case Decl::ObjCImplementation:
19443 ResetObjCLayout(cast<ObjCImplementationDecl>(DC)->getClassInterface());
19449 CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(EnclosingDecl);
19453 unsigned NumNamedMembers = 0;
19455 for (
const auto *I :
Record->decls()) {
19456 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
19457 if (IFD->getDeclName())
19474 RecFields.push_back(FD);
19494 bool IsLastField = (i + 1 == Fields.end());
19503 (
Record || isa<ObjCContainerDecl>(EnclosingDecl))) {
19509 unsigned DiagID = 0;
19510 if (!
Record->isUnion() && !IsLastField) {
19513 << llvm::to_underlying(
Record->getTagKind());
19514 Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
19518 }
else if (
Record->isUnion())
19519 DiagID = getLangOpts().MicrosoftExt
19520 ? diag::ext_flexible_array_union_ms
19521 : diag::ext_flexible_array_union_gnu;
19522 else if (NumNamedMembers < 1)
19523 DiagID = getLangOpts().MicrosoftExt
19524 ? diag::ext_flexible_array_empty_aggregate_ms
19525 : diag::ext_flexible_array_empty_aggregate_gnu;
19535 if (CXXRecord && CXXRecord->getNumVBases() != 0)
19538 if (!getLangOpts().
C99)
19549 Diag(FD->
getLocation(), diag::err_flexible_array_has_nontrivial_dtor)
19556 Record->setHasFlexibleArrayMember(
true);
19563 RequireCompleteSizedType(
19565 diag::err_field_incomplete_or_sizeless)) {
19571 if (
Record && FDTTy->getDecl()->hasFlexibleArrayMember()) {
19574 Record->setHasFlexibleArrayMember(
true);
19575 if (!
Record->isUnion()) {
19590 if (isa<ObjCContainerDecl>(EnclosingDecl) &&
19592 diag::err_abstract_type_in_decl,
19593 AbstractIvarType)) {
19597 if (
Record && FDTTy->getDecl()->hasObjectMember())
19598 Record->setHasObjectMember(
true);
19599 if (
Record && FDTTy->getDecl()->hasVolatileMember())
19600 Record->setHasVolatileMember(
true);
19609 getSourceManager().isInSystemHeader(FD->
getLocation()) &&
19619 FD->
addAttr(UnavailableAttr::CreateImplicit(
19620 Context,
"", UnavailableAttr::IR_ARCFieldWithOwnership,
19622 }
else if (getLangOpts().ObjC &&
19624 !
Record->hasObjectMember()) {
19627 Record->setHasObjectMember(
true);
19632 Record->setHasObjectMember(
true);
19635 Record->setHasObjectMember(
true);
19640 !shouldIgnoreForRecordTriviality(FD)) {
19643 Record->setNonTrivialToPrimitiveDefaultInitialize(
true);
19646 Record->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(
true);
19650 Record->setNonTrivialToPrimitiveCopy(
true);
19652 Record->setHasNonTrivialToPrimitiveCopyCUnion(
true);
19655 Record->setNonTrivialToPrimitiveDestroy(
true);
19656 Record->setParamDestroyedInCallee(
true);
19658 Record->setHasNonTrivialToPrimitiveDestructCUnion(
true);
19662 if (RT->getDecl()->getArgPassingRestrictions() ==
19664 Record->setArgPassingRestrictions(
19667 Record->setArgPassingRestrictions(
19672 Record->setHasVolatileMember(
true);
19680 bool Completed =
false;
19684 Parent->isTemplateParamScope())
19685 Record->setInvalidDecl();
19689 if (!CXXRecord->isInvalidDecl()) {
19692 I = CXXRecord->conversion_begin(),
19693 E = CXXRecord->conversion_end(); I != E; ++I)
19694 I.setAccess((*I)->getAccess());
19698 AddImplicitlyDeclaredMembersToClass(CXXRecord);
19700 if (!CXXRecord->isDependentType()) {
19701 if (!CXXRecord->isInvalidDecl()) {
19705 if (CXXRecord->getNumVBases()) {
19707 CXXRecord->getFinalOverriders(FinalOverriders);
19709 for (CXXFinalOverriderMap::iterator M = FinalOverriders.begin(),
19710 MEnd = FinalOverriders.end();
19713 SOEnd = M->second.end();
19714 SO != SOEnd; ++SO) {
19715 assert(SO->second.size() > 0 &&
19716 "Virtual function without overriding functions?");
19717 if (SO->second.size() == 1)
19724 Diag(
Record->getLocation(), diag::err_multiple_final_overriders)
19726 Diag(M->first->getLocation(),
19727 diag::note_overridden_virtual_function);
19729 OM = SO->second.begin(),
19730 OMEnd = SO->second.end();
19732 Diag(OM->Method->getLocation(), diag::note_final_overrider)
19733 << (
const NamedDecl *)M->first << OM->Method->getParent();
19735 Record->setInvalidDecl();
19738 CXXRecord->completeDefinition(&FinalOverriders);
19748 Record->completeDefinition();
19751 ProcessDeclAttributeList(S,
Record, Attrs);
19754 auto IsFunctionPointerOrForwardDecl = [&](
const Decl *D) {
19755 const FieldDecl *FD = dyn_cast<FieldDecl>(D);
19768 if (
const auto *TD = dyn_cast<TagDecl>(D))
19769 return !TD->isCompleteDefinition();
19773 if (isa<PointerType>(FieldType)) {
19783 (
Record->hasAttr<RandomizeLayoutAttr>() ||
19784 (!
Record->hasAttr<NoRandomizeLayoutAttr>() &&
19785 llvm::all_of(
Record->decls(), IsFunctionPointerOrForwardDecl))) &&
19786 !
Record->isUnion() && !getLangOpts().RandstructSeed.empty() &&
19787 !
Record->isRandomized()) {
19791 Record->reorderDecls(NewDeclOrdering);
19796 auto *Dtor = CXXRecord->getDestructor();
19797 if (Dtor && Dtor->isImplicit() &&
19799 CXXRecord->setImplicitDestructorIsDeleted();
19800 SetDeclDeleted(Dtor, CXXRecord->getLocation());
19804 if (
Record->hasAttrs()) {
19805 CheckAlignasUnderalignment(
Record);
19807 if (
const MSInheritanceAttr *IA =
Record->getAttr<MSInheritanceAttr>())
19808 checkMSInheritanceAttrOnDefinition(cast<CXXRecordDecl>(
Record),
19809 IA->getRange(), IA->getBestCase(),
19810 IA->getInheritanceModel());
19816 bool CheckForZeroSize;
19818 CheckForZeroSize =
true;
19823 CXXRecord->getLexicalDeclContext()->isExternCContext() &&
19824 !CXXRecord->isDependentType() && !inTemplateInstantiation() &&
19825 CXXRecord->isCLike();
19827 if (CheckForZeroSize) {
19828 bool ZeroSize =
true;
19829 bool IsEmpty =
true;
19830 unsigned NonBitFields = 0;
19832 E =
Record->field_end();
19833 (NonBitFields == 0 || ZeroSize) && I != E; ++I) {
19835 if (I->isUnnamedBitField()) {
19836 if (!I->isZeroLengthBitField(Context))
19840 QualType FieldType = I->getType();
19852 diag::warn_zero_size_struct_union_in_extern_c :
19853 diag::warn_zero_size_struct_union_compat)
19854 << IsEmpty <<
Record->isUnion() << (NonBitFields > 1);
19859 if (NonBitFields == 0 && !getLangOpts().CPlusPlus) {
19860 Diag(RecLoc, IsEmpty ? diag::ext_empty_struct_union :
19861 diag::ext_no_named_members_in_struct_union)
19869 ID->setEndOfDefinitionLoc(RBrac);
19871 for (
unsigned i = 0, e = RecFields.size(); i != e; ++i) {
19873 ID->addDecl(ClsFields[i]);
19877 if (
ID->getSuperClass())
19878 DiagnoseDuplicateIvars(
ID,
ID->getSuperClass());
19880 dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
19881 assert(IMPDecl &&
"ActOnFields - missing ObjCImplementationDecl");
19882 for (
unsigned I = 0, N = RecFields.size(); I != N; ++I)
19886 CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
19887 IMPDecl->setIvarLBraceLoc(LBrac);
19888 IMPDecl->setIvarRBraceLoc(RBrac);
19890 dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
19898 for (
unsigned i = 0, e = RecFields.size(); i != e; ++i) {
19902 Diag(ClsFields[i]->getLocation(),
19903 diag::err_duplicate_ivar_declaration);
19904 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
19910 Diag(ClsFields[i]->getLocation(),
19911 diag::err_duplicate_ivar_declaration);
19912 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
19918 CDecl->addDecl(ClsFields[i]);
19920 CDecl->setIvarLBraceLoc(LBrac);
19921 CDecl->setIvarRBraceLoc(RBrac);
19933 "Integral type required!");
19936 if (
Value.isUnsigned() ||
Value.isNonNegative()) {
19939 return Value.getActiveBits() <= BitWidth;
19941 return Value.getSignificantBits() <= BitWidth;
19951 const unsigned NumTypes = 4;
19952 QualType SignedIntegralTypes[NumTypes] = {
19955 QualType UnsignedIntegralTypes[NumTypes] = {
19962 : UnsignedIntegralTypes;
19963 for (
unsigned I = 0; I != NumTypes; ++I)
19979 if (Val && DiagnoseUnexpandedParameterPack(Val, UPPC_EnumeratorValue))
19983 Val = DefaultLvalueConversion(Val).get();
19992 if (getLangOpts().
CPlusPlus11 && Enum->isFixed()) {
19996 EltTy = Enum->getIntegerType();
20003 Val = Converted.
get();
20006 VerifyIntegerConstantExpression(Val, &EnumVal, AllowFold)
20010 if (Enum->isComplete()) {
20011 EltTy = Enum->getIntegerType();
20020 .isWindowsMSVCEnvironment()) {
20021 Diag(IdLoc, diag::ext_enumerator_too_large) << EltTy;
20023 Diag(IdLoc, diag::err_enumerator_too_large) << EltTy;
20028 Val = ImpCastExprToType(Val, EltTy,
20047 Diag(IdLoc, diag::ext_enum_value_not_int)
20049 << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
20052 Val = ImpCastExprToType(Val, Context.
IntTy, CK_IntegralCast).get();
20061 if (Enum->isDependentType())
20063 else if (!LastEnumConst) {
20072 if (Enum->isFixed()) {
20073 EltTy = Enum->getIntegerType();
20076 EltTy = Context.
IntTy;
20082 EltTy = LastEnumConst->
getType();
20085 if (EnumVal < LastEnumConst->getInitVal()) {
20097 if (
T.isNull() || Enum->isFixed()) {
20101 EnumVal = EnumVal.zext(EnumVal.getBitWidth() * 2);
20103 if (Enum->isFixed())
20105 Diag(IdLoc, diag::err_enumerator_wrapped)
20109 Diag(IdLoc, diag::ext_enumerator_increment_too_large)
20120 EnumVal = EnumVal.zextOrTrunc(Context.
getIntWidth(EltTy));
20128 if (!getLangOpts().
CPlusPlus && !
T.isNull())
20129 Diag(IdLoc, diag::warn_enum_value_overflow);
20134 Diag(IdLoc, diag::ext_enum_value_not_int)
20143 EnumVal = EnumVal.extOrTrunc(Context.
getIntWidth(EltTy));
20153 if (!(getLangOpts().Modules || getLangOpts().ModulesLocalVisibility) ||
20160 NamedDecl *PrevDecl = LookupSingleName(S, II, IILoc, LookupOrdinaryName,
20161 forRedeclarationInCurContext());
20162 auto *PrevECD = dyn_cast_or_null<EnumConstantDecl>(PrevDecl);
20166 EnumDecl *PrevED = cast<EnumDecl>(PrevECD->getDeclContext());
20168 if (!PrevED->
getDeclName() && !hasVisibleDefinition(PrevED, &Hidden)) {
20181 EnumDecl *TheEnumDecl = cast<EnumDecl>(theEnumDecl);
20183 cast_or_null<EnumConstantDecl>(lastEnumConst);
20187 S = getNonFieldDeclScope(S);
20198 DiagnoseTemplateParameterShadow(IdLoc, PrevDecl);
20200 PrevDecl =
nullptr;
20213 CheckEnumConstant(TheEnumDecl, LastEnumConst, IdLoc,
Id, Val);
20218 if (!TheEnumDecl->
isScoped() && isa<ValueDecl>(PrevDecl)) {
20220 CheckShadow(New, PrevDecl, R);
20225 assert((getLangOpts().
CPlusPlus || !isa<TagDecl>(PrevDecl)) &&
20226 "Received TagDecl when not in C++!");
20227 if (!isa<TagDecl>(PrevDecl) && isDeclInScope(PrevDecl, CurContext, S)) {
20228 if (isa<EnumConstantDecl>(PrevDecl))
20229 Diag(IdLoc, diag::err_redefinition_of_enumerator) <<
Id;
20231 Diag(IdLoc, diag::err_redefinition) <<
Id;
20232 notePreviousDefinition(PrevDecl, IdLoc);
20238 ProcessDeclAttributeList(S, New, Attrs);
20239 AddPragmaAttributes(S, New);
20244 PushOnScopeChains(New, S);
20246 ActOnDocumentableDecl(New);
20264 if (!BO->isAdditiveOp())
20272 InitExpr = BO->getLHS();
20276 DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(InitExpr);
20296 if (!Enum->getIdentifier())
20300 if (Enum->getNumPositiveBits() > 63 || Enum->getNumNegativeBits() > 64)
20303 if (S.
Diags.
isIgnored(diag::warn_duplicate_enum_values, Enum->getLocation()))
20309 typedef llvm::PointerUnion<EnumConstantDecl*, ECDVector*> DeclOrVector;
20312 typedef std::unordered_map<int64_t, DeclOrVector> ValueToVectorMap;
20317 return Val.isSigned() ? Val.getSExtValue() : Val.getZExtValue();
20320 DuplicatesVector DupVector;
20321 ValueToVectorMap EnumMap;
20325 for (
auto *Element : Elements) {
20339 EnumMap.insert({EnumConstantToKey(ECD), ECD});
20342 if (EnumMap.size() == 0)
20346 for (
auto *Element : Elements) {
20352 auto Iter = EnumMap.find(EnumConstantToKey(ECD));
20353 if (
Iter == EnumMap.end())
20356 DeclOrVector& Entry =
Iter->second;
20363 auto Vec = std::make_unique<ECDVector>();
20365 Vec->push_back(ECD);
20372 DupVector.emplace_back(std::move(Vec));
20376 ECDVector *Vec = Entry.get<ECDVector*>();
20378 if (*Vec->begin() == ECD)
20381 Vec->push_back(ECD);
20385 for (
const auto &Vec : DupVector) {
20386 assert(Vec->size() > 1 &&
"ECDVector should have at least 2 elements.");
20389 auto *FirstECD = Vec->front();
20390 S.
Diag(FirstECD->getLocation(), diag::warn_duplicate_enum_values)
20391 << FirstECD <<
toString(FirstECD->getInitVal(), 10)
20392 << FirstECD->getSourceRange();
20396 for (
auto *ECD : llvm::drop_begin(*Vec))
20397 S.
Diag(ECD->getLocation(), diag::note_duplicate_element)
20398 << ECD <<
toString(ECD->getInitVal(), 10)
20399 << ECD->getSourceRange();
20404 bool AllowMask)
const {
20405 assert(ED->
isClosedFlag() &&
"looking for value in non-flag or open enum");
20408 auto R = FlagBitsCache.insert(std::make_pair(ED,
llvm::APInt()));
20413 const auto &EVal = E->getInitVal();
20415 if (EVal.isPowerOf2())
20416 FlagBits = FlagBits.zext(EVal.getBitWidth()) | EVal;
20428 llvm::APInt FlagMask = ~FlagBits.zextOrTrunc(Val.getBitWidth());
20429 return !(FlagMask & Val) || (AllowMask && !(FlagMask & ~Val));
20435 EnumDecl *Enum = cast<EnumDecl>(EnumDeclX);
20438 ProcessDeclAttributeList(S, Enum, Attrs);
20441 if (Enum->isDependentType()) {
20442 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
20444 cast_or_null<EnumConstantDecl>(Elements[i]);
20445 if (!ECD)
continue;
20463 unsigned NumNegativeBits = 0;
20464 unsigned NumPositiveBits = 0;
20466 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
20468 cast_or_null<EnumConstantDecl>(Elements[i]);
20469 if (!ECD)
continue;
20474 if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
20477 unsigned ActiveBits = InitVal.getActiveBits();
20478 NumPositiveBits =
std::max({NumPositiveBits, ActiveBits, 1u});
20481 std::max(NumNegativeBits, (
unsigned)InitVal.getSignificantBits());
20489 if (!NumPositiveBits && !NumNegativeBits)
20490 NumPositiveBits = 1;
20494 unsigned BestWidth;
20507 bool Packed = Enum->hasAttr<PackedAttr>();
20510 if (LangOpts.ShortEnums)
20515 if (Enum->isComplete()) {
20516 BestType = Enum->getIntegerType();
20520 BestPromotionType = BestType;
20524 else if (NumNegativeBits) {
20528 if (Packed && NumNegativeBits <= CharWidth && NumPositiveBits < CharWidth) {
20530 BestWidth = CharWidth;
20531 }
else if (Packed && NumNegativeBits <= ShortWidth &&
20532 NumPositiveBits < ShortWidth) {
20534 BestWidth = ShortWidth;
20535 }
else if (NumNegativeBits <= IntWidth && NumPositiveBits < IntWidth) {
20536 BestType = Context.
IntTy;
20537 BestWidth = IntWidth;
20541 if (NumNegativeBits <= BestWidth && NumPositiveBits < BestWidth) {
20542 BestType = Context.
LongTy;
20546 if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
20547 Diag(Enum->getLocation(), diag::ext_enum_too_large);
20551 BestPromotionType = (BestWidth <= IntWidth ? Context.
IntTy : BestType);
20556 if (Packed && NumPositiveBits <= CharWidth) {
20558 BestPromotionType = Context.
IntTy;
20559 BestWidth = CharWidth;
20560 }
else if (Packed && NumPositiveBits <= ShortWidth) {
20562 BestPromotionType = Context.
IntTy;
20563 BestWidth = ShortWidth;
20564 }
else if (NumPositiveBits <= IntWidth) {
20566 BestWidth = IntWidth;
20568 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
20570 }
else if (NumPositiveBits <=
20574 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
20578 if (NumPositiveBits > BestWidth) {
20583 Diag(Enum->getLocation(), diag::ext_enum_too_large);
20587 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
20594 for (
auto *D : Elements) {
20595 auto *ECD = cast_or_null<EnumConstantDecl>(D);
20596 if (!ECD)
continue;
20613 !Enum->isFixed() &&
20615 NewTy = Context.
IntTy;
20616 NewWidth = IntWidth;
20618 }
else if (ECD->getType() == BestType) {
20628 NewWidth = BestWidth;
20633 InitVal = InitVal.extOrTrunc(NewWidth);
20634 InitVal.setIsSigned(NewSign);
20635 ECD->setInitVal(Context, InitVal);
20638 if (ECD->getInitExpr() &&
20639 !Context.
hasSameType(NewTy, ECD->getInitExpr()->getType()))
20641 Context, NewTy, CK_IntegralCast, ECD->getInitExpr(),
20649 ECD->setType(NewTy);
20652 Enum->completeDefinition(BestType, BestPromotionType,
20653 NumPositiveBits, NumNegativeBits);
20657 if (Enum->isClosedFlag()) {
20658 for (
Decl *D : Elements) {
20660 if (!ECD)
continue;
20663 if (InitVal != 0 && !InitVal.isPowerOf2() &&
20664 !IsValueInFlagEnum(Enum, InitVal,
true))
20671 if (Enum->hasAttrs())
20672 CheckAlignasUnderalignment(Enum);
20681 AsmString, StartLoc,
20683 CurContext->addDecl(New);
20689 CurContext->addDecl(New);
20690 PushDeclContext(S, New);
20691 PushFunctionScope();
20692 PushCompoundScope(
false);
20698 PopCompoundScope();
20699 PopFunctionScopeInfo();
20708 NamedDecl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
20709 LookupOrdinaryName);
20712 AsmLabelAttr *
Attr = AsmLabelAttr::CreateImplicit(
20713 Context, AliasName->
getName(),
true, Info);
20719 if (PrevDecl && (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl))) {
20723 Diag(PrevDecl->
getLocation(), diag::warn_redefine_extname_not_applied)
20724 << (isa<FunctionDecl>(PrevDecl) ? 0 : 1) << PrevDecl;
20727 (
void)ExtnameUndeclaredIdentifiers.insert(std::make_pair(Name,
Attr));
20733 Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc, LookupOrdinaryName);
20736 PrevDecl->
addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc));
20738 (void)WeakUndeclaredIdentifiers[Name].insert(
WeakInfo(
nullptr, NameLoc));
20747 Decl *PrevDecl = LookupSingleName(TUScope, AliasName, AliasNameLoc,
20748 LookupOrdinaryName);
20751 if (PrevDecl && (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl))) {
20752 if (!PrevDecl->
hasAttr<AliasAttr>())
20753 if (
NamedDecl *ND = dyn_cast<NamedDecl>(PrevDecl))
20754 DeclApplyPragmaWeak(TUScope, ND, W);
20756 (void)WeakUndeclaredIdentifiers[AliasName].insert(W);
20761 return (dyn_cast_or_null<ObjCContainerDecl>(CurContext));
20766 if (FD->
hasAttr<SYCLSimdAttr>())
20768 if (FD->
hasAttr<SYCLDeviceAttr>() || FD->
hasAttr<SYCLKernelAttr>())
20771 if (getLangOpts().
CUDA)
20774 if (getLangOpts().OpenMP)
20775 return getLangOpts().OpenMPIsTargetDevice
20783 assert(FD &&
"Expected non-null FunctionDecl");
20787 return FunctionEmissionStatus::TemplateDiscarded;
20789 if (LangOpts.SYCLIsDevice &&
20790 (FD->
hasAttr<SYCLDeviceAttr>() || FD->
hasAttr<SYCLKernelAttr>()))
20791 return FunctionEmissionStatus::Emitted;
20794 auto IsEmittedForExternalSymbol = [
this, FD]() {
20801 getASTContext().GetGVALinkageForFunction(Def));
20804 if (LangOpts.OpenMPIsTargetDevice) {
20807 std::optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
20814 if (*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
20815 return FunctionEmissionStatus::OMPDiscarded;
20818 if (OpenMP().isInOpenMPDeclareTargetContext() || DevTy)
20819 if (IsEmittedForExternalSymbol())
20820 return FunctionEmissionStatus::Emitted;
20824 return FunctionEmissionStatus::OMPDiscarded;
20825 }
else if (LangOpts.OpenMP > 45) {
20829 std::optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
20832 if (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost)
20833 return FunctionEmissionStatus::OMPDiscarded;
20836 if (Final && LangOpts.OpenMP && !LangOpts.CUDA)
20837 return FunctionEmissionStatus::Emitted;
20839 if (LangOpts.CUDA) {
20846 return FunctionEmissionStatus::CUDADiscarded;
20847 if (!LangOpts.CUDAIsDevice &&
20849 return FunctionEmissionStatus::CUDADiscarded;
20851 if (IsEmittedForExternalSymbol())
20852 return FunctionEmissionStatus::Emitted;
20855 if (getLangOpts().SYCLIsDevice) {
20856 if (!FD->
hasAttr<SYCLDeviceAttr>() && !FD->
hasAttr<SYCLKernelAttr>())
20869 return FunctionEmissionStatus::Emitted;
20885 return LangOpts.CUDA && !LangOpts.CUDAIsDevice &&
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
static constexpr Builtin::Info BuiltinInfo[]
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines helper utilities for supporting the HLSL runtime environment.
static const Decl * getCanonicalDecl(const Decl *D)
static const GlobalDecl isTemplate(GlobalDecl GD, const TemplateArgumentList *&TemplateArgs)
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Architecture Architecture
llvm::MachO::Target Target
llvm::MachO::Record Record
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::Preprocessor interface.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
@ NotForRedeclaration
The lookup is a reference to this name that is not for the purpose of redeclaring the name.
@ ForExternalRedeclaration
The lookup results will be used for redeclaration of a name with external linkage; non-visible lookup...
@ ForVisibleRedeclaration
The lookup results will be used for redeclaration of a name, if an entity by that name already exists...
static void ProcessAPINotes(Sema &S, Decl *D, const api_notes::CommonEntityInfo &Info, VersionedInfoMetadata Metadata)
This file declares semantic analysis for CUDA constructs.
static void diagnoseImplicitlyRetainedSelf(Sema &S)
static void SetNestedNameSpecifier(Sema &S, DeclaratorDecl *DD, Declarator &D)
static UnqualifiedTypeNameLookupResult lookupUnqualifiedTypeNameInBase(Sema &S, const IdentifierInfo &II, SourceLocation NameLoc, const CXXRecordDecl *RD)
Tries to perform unqualified lookup of the type decls in bases for dependent class.
static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD, const FunctionDecl *&PossiblePrototype)
static bool PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl *FD)
static ParsedType recoverFromTypeInKnownDependentBase(Sema &S, const IdentifierInfo &II, SourceLocation NameLoc)
static void mergeParamDeclTypes(ParmVarDecl *NewParam, const ParmVarDecl *OldParam, Sema &S)
static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD, DeclaratorDecl *OldD)
If necessary, adjust the semantic declaration context for a qualified declaration to name the correct...
static bool isResultTypeOrTemplate(LookupResult &R, const Token &NextToken)
Determine whether the given result set contains either a type name or.
static void FixInvalidVariablyModifiedTypeLoc(TypeLoc SrcTL, TypeLoc DstTL)
static bool AllowOverloadingOfFunction(const LookupResult &Previous, ASTContext &Context, const FunctionDecl *New)
Determine whether overloading is allowed for a new function declaration considering prior declaration...
static StringRef getHeaderName(Builtin::Context &BuiltinInfo, unsigned ID, ASTContext::GetBuiltinTypeError Error)
static StorageClass getFunctionStorageClass(Sema &SemaRef, Declarator &D)
static bool checkUsingShadowRedecl(Sema &S, UsingShadowDecl *OldS, ExpectedDecl *New)
Check whether a redeclaration of an entity introduced by a using-declaration is valid,...
static bool mergeDeclAttribute(Sema &S, NamedDecl *D, const InheritableAttr *Attr, Sema::AvailabilityMergeKind AMK)
static ShadowedDeclKind computeShadowedDeclKind(const NamedDecl *ShadowedDecl, const DeclContext *OldDC)
Determine what kind of declaration we're shadowing.
static void checkIsValidOpenCLKernelParameter(Sema &S, Declarator &D, ParmVarDecl *Param, llvm::SmallPtrSetImpl< const Type * > &ValidTypes)
static void mergeParamDeclAttributes(ParmVarDecl *newDecl, const ParmVarDecl *oldDecl, Sema &S)
mergeParamDeclAttributes - Copy attributes from the old parameter to the new one.
void emitReadOnlyPlacementAttrWarning(Sema &S, const VarDecl *VD)
static bool CheckC23ConstexprVarType(Sema &SemaRef, SourceLocation VarLoc, QualType T)
static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD, bool &Redeclaration, NamedDecl *&OldDecl, LookupResult &Previous)
Check the validity of a mulitversion function declaration.
static bool mergeAlignedAttrs(Sema &S, NamedDecl *New, Decl *Old)
Merge alignment attributes from Old to New, taking into account the special semantics of C11's _Align...
static bool mergeTypeWithPrevious(Sema &S, VarDecl *NewVD, VarDecl *OldVD, LookupResult &Previous)
static void CheckConstPureAttributesUsage(Sema &S, FunctionDecl *NewFD)
static bool FindPossiblePrototype(const FunctionDecl *FD, const FunctionDecl *&PossiblePrototype)
static bool MultiVersionTypesCompatible(FunctionDecl *Old, FunctionDecl *New)
static void GenerateFixForUnusedDecl(const NamedDecl *D, ASTContext &Ctx, FixItHint &Hint)
static void CheckExplicitObjectParameter(Sema &S, ParmVarDecl *P, SourceLocation ExplicitThisLoc)
static void patchDefaultTargetVersion(FunctionDecl *From, FunctionDecl *To)
static bool isFunctionDefinitionDiscarded(Sema &S, FunctionDecl *FD)
Given that we are within the definition of the given function, will that definition behave like C99's...
static bool isRepresentableIntegerValue(ASTContext &Context, llvm::APSInt &Value, QualType T)
Determine whether the given integral value is representable within the given type T.
static void CheckForDuplicateEnumValues(Sema &S, ArrayRef< Decl * > Elements, EnumDecl *Enum, QualType EnumType)
static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec &DS)
static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old)
checkNewAttributesAfterDef - If we already have a definition, check that there are no new attributes ...
static bool isClassCompatTagKind(TagTypeKind Tag)
Determine if tag kind is a class-key compatible with class for redeclaration (class,...
static bool hasIdenticalPassObjectSizeAttrs(const FunctionDecl *A, const FunctionDecl *B)
static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND)
static bool hasSimilarParameters(ASTContext &Context, FunctionDecl *Declaration, FunctionDecl *Definition, SmallVectorImpl< unsigned > &Params)
hasSimilarParameters - Determine whether the C++ functions Declaration and Definition have "nearly" m...
static bool isDeclExternC(const Decl *D)
Returns true if given declaration has external C language linkage.
static NonCLikeKind getNonCLikeKindForAnonymousStruct(const CXXRecordDecl *RD)
Determine whether a class is C-like, according to the rules of C++ [dcl.typedef] for anonymous classe...
static bool methodHasName(const FunctionDecl *FD, StringRef Name)
static bool checkForConflictWithNonVisibleExternC(Sema &S, const T *ND, LookupResult &Previous)
Apply special rules for handling extern "C" declarations.
static bool DeclHasAttr(const Decl *D, const Attr *A)
DeclhasAttr - returns true if decl Declaration already has the target attribute.
static bool isOpenCLSizeDependentType(ASTContext &C, QualType Ty)
static void diagnoseMissingConstinit(Sema &S, const VarDecl *InitDecl, const ConstInitAttr *CIAttr, bool AttrBeforeInit)
static bool shouldWarnIfShadowedDecl(const DiagnosticsEngine &Diags, const LookupResult &R)
static FixItHint createFriendTagNNSFixIt(Sema &SemaRef, NamedDecl *ND, Scope *S, SourceLocation NameLoc)
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
static bool CheckAnonMemberRedeclaration(Sema &SemaRef, Scope *S, DeclContext *Owner, DeclarationName Name, SourceLocation NameLoc, bool IsUnion, StorageClass SC)
We are trying to inject an anonymous member into the given scope; check if there's an existing declar...
static bool checkGlobalOrExternCConflict(Sema &S, const T *ND, bool IsGlobal, LookupResult &Previous)
Check for conflict between this global or extern "C" declaration and previous global or extern "C" de...
static bool ShouldDiagnoseUnusedDecl(const LangOptions &LangOpts, const NamedDecl *D)
static bool isStdBuiltin(ASTContext &Ctx, FunctionDecl *FD, unsigned BuiltinID)
Determine whether a declaration matches a known function in namespace std.
static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, DeclContext *Owner, RecordDecl *AnonRecord, AccessSpecifier AS, StorageClass SC, SmallVectorImpl< NamedDecl * > &Chaining)
InjectAnonymousStructOrUnionMembers - Inject the members of the anonymous struct or union AnonRecord ...
@ InvalidAddrSpacePtrKernelParam
static bool isFromSystemHeader(SourceManager &SM, const Decl *D)
Returns true if the declaration is declared in a system header or from a system macro.
static bool AreSpecialMemberFunctionsSameKind(ASTContext &Context, CXXMethodDecl *M1, CXXMethodDecl *M2, CXXSpecialMemberKind CSM)
[class.mem.special]p5 Two special member functions are of the same kind if:
static const CXXRecordDecl * findRecordWithDependentBasesOfEnclosingMethod(const DeclContext *DC)
Find the parent class with dependent bases of the innermost enclosing method context.
static void ComputeSelectedDestructor(Sema &S, CXXRecordDecl *Record)
[class.dtor]p4: At the end of the definition of a class, overload resolution is performed among the p...
static bool shouldConsiderLinkage(const VarDecl *VD)
static SourceLocation findDefaultInitializer(const CXXRecordDecl *Record)
static bool CheckMultiVersionAdditionalRules(Sema &S, const FunctionDecl *OldFD, const FunctionDecl *NewFD, bool CausesMV, MultiVersionKind MVKind)
static bool EquivalentArrayTypes(QualType Old, QualType New, const ASTContext &Ctx)
static bool haveIncompatibleLanguageLinkages(const T *Old, const T *New)
static unsigned getRedeclDiagFromTagKind(TagTypeKind Tag)
Get diagnostic select index for tag kind for redeclaration diagnostic message.
static void CheckPoppedLabel(LabelDecl *L, Sema &S, Sema::DiagReceiverTy DiagReceiver)
static void diagnoseVarDeclTypeMismatch(Sema &S, VarDecl *New, VarDecl *Old)
static bool RebuildDeclaratorInCurrentInstantiation(Sema &S, Declarator &D, DeclarationName Name)
RebuildDeclaratorInCurrentInstantiation - Checks whether the given declarator needs to be rebuilt in ...
static void SetEligibleMethods(Sema &S, CXXRecordDecl *Record, ArrayRef< CXXMethodDecl * > Methods, CXXSpecialMemberKind CSM)
[class.mem.special]p6: An eligible special member function is a special member function for which:
static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result, Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, SourceLocation NameLoc)
static bool hasParsedAttr(Scope *S, const Declarator &PD, ParsedAttr::Kind Kind)
ShadowedDeclKind
Enum describing the select options in diag::warn_decl_shadow.
static std::pair< diag::kind, SourceLocation > getNoteDiagForInvalidRedeclaration(const T *Old, const T *New)
static unsigned getMSManglingNumber(const LangOptions &LO, Scope *S)
static NestedNameSpecifier * synthesizeCurrentNestedNameSpecifier(ASTContext &Context, DeclContext *DC)
static bool canRedefineFunction(const FunctionDecl *FD, const LangOptions &LangOpts)
canRedefineFunction - checks if a function can be redefined.
static ObjCIvarDecl::AccessControl TranslateIvarVisibility(tok::ObjCKeywordKind ivarVisibility)
TranslateIvarVisibility - Translate visibility from a token ID to an AST enum value.
static NamedDecl * DiagnoseInvalidRedeclaration(Sema &SemaRef, LookupResult &Previous, FunctionDecl *NewFD, ActOnFDArgs &ExtraArgs, bool IsLocalFriend, Scope *S)
Generate diagnostics for an invalid function redeclaration.
static OpenCLParamType getOpenCLKernelParameterType(Sema &S, QualType PT)
static void checkDuplicateDefaultInit(Sema &S, CXXRecordDecl *Parent, SourceLocation DefaultInitLoc)
static bool isDefaultStdCall(FunctionDecl *FD, Sema &S)
static TypeSourceInfo * TryToFixInvalidVariablyModifiedTypeSourceInfo(TypeSourceInfo *TInfo, ASTContext &Context, bool &SizeIsNegative, llvm::APSInt &Oversized)
Helper method to turn variable array types into constant array types in certain situations which woul...
static Attr * getImplicitCodeSegAttrFromClass(Sema &S, const FunctionDecl *FD)
Return a CodeSegAttr from a containing class.
static bool diagnoseOpenCLTypes(Sema &Se, VarDecl *NewVD)
Returns true if there hasn't been any invalid type diagnosed.
static void RemoveUsingDecls(LookupResult &R)
Removes using shadow declarations not at class scope from the lookup results.
static void ComputeSpecialMemberFunctionsEligiblity(Sema &S, CXXRecordDecl *Record)
static bool AttrCompatibleWithMultiVersion(attr::Kind Kind, MultiVersionKind MVKind)
static bool isUsingDeclNotAtClassScope(NamedDecl *D)
static void filterNonConflictingPreviousTypedefDecls(Sema &S, TypedefNameDecl *Decl, LookupResult &Previous)
Typedef declarations don't have linkage, but they still denote the same entity if their types are the...
static QualType TryToFixInvalidVariablyModifiedType(QualType T, ASTContext &Context, bool &SizeIsNegative, llvm::APSInt &Oversized)
Helper method to turn variable array types into constant array types in certain situations which woul...
static bool hasDeducedAuto(DeclaratorDecl *DD)
static void copyAttrFromTypedefToDecl(Sema &S, Decl *D, const TypedefType *TT)
static QualType getCoreType(QualType Ty)
static bool CheckTargetCausesMultiVersioning(Sema &S, FunctionDecl *OldFD, FunctionDecl *NewFD, bool &Redeclaration, NamedDecl *&OldDecl, LookupResult &Previous)
static bool isMainFileLoc(const Sema &S, SourceLocation Loc)
static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD)
Check the target or target_version attribute of the function for MultiVersion validity.
static bool isOutOfScopePreviousDeclaration(NamedDecl *, DeclContext *, ASTContext &)
Determines whether the given declaration is an out-of-scope previous declaration.
static StorageClass StorageClassSpecToVarDeclStorageClass(const DeclSpec &DS)
StorageClassSpecToVarDeclStorageClass - Maps a DeclSpec::SCS to a VarDecl::StorageClass.
static ParsedType buildNamedType(Sema &S, const CXXScopeSpec *SS, QualType T, SourceLocation NameLoc, bool WantNontrivialTypeSourceInfo=true)
Build a ParsedType for a simple-type-specifier with a nested-name-specifier.
static DeclContext * getTagInjectionContext(DeclContext *DC)
Find the DeclContext in which a tag is implicitly declared if we see an elaborated type specifier in ...
static bool CheckMultiVersionAdditionalDecl(Sema &S, FunctionDecl *OldFD, FunctionDecl *NewFD, const CPUDispatchAttr *NewCPUDisp, const CPUSpecificAttr *NewCPUSpec, const TargetClonesAttr *NewClones, bool &Redeclaration, NamedDecl *&OldDecl, LookupResult &Previous)
Check the validity of a new function declaration being added to an existing multiversioned declaratio...
static SourceLocation getCaptureLocation(const LambdaScopeInfo *LSI, const VarDecl *VD)
Return the location of the capture if the given lambda captures the given variable VD,...
static FunctionDecl * CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, DeclContext *DC, QualType &R, TypeSourceInfo *TInfo, StorageClass SC, bool &IsVirtualOkay)
static bool CheckMultiVersionFirstFunction(Sema &S, FunctionDecl *FD)
Check the validity of a multiversion function declaration that is the first of its kind.
static const NamedDecl * getDefinition(const Decl *D)
static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl, NamedDecl *NewDecl, bool IsSpecialization, bool IsDefinition)
static Scope * getTagInjectionScope(Scope *S, const LangOptions &LangOpts)
Find the Scope in which a tag is implicitly declared if we see an elaborated type specifier in the sp...
static bool checkNonMultiVersionCompatAttributes(Sema &S, const FunctionDecl *FD, const FunctionDecl *CausedFD, MultiVersionKind MVKind)
static bool ValidDuplicateEnum(EnumConstantDecl *ECD, EnumDecl *Enum)
static QualType getNextLargerIntegralType(ASTContext &Context, QualType T)
static bool isExternC(T *D)
static bool isIncompleteDeclExternC(Sema &S, const T *D)
Determine whether a variable is extern "C" prior to attaching an initializer.
static bool isAttributeTargetADefinition(Decl *D)
static bool IsDisallowedCopyOrAssign(const CXXMethodDecl *D)
Check for this common pattern:
static bool isAcceptableTagRedeclContext(Sema &S, DeclContext *OldDC, DeclContext *NewDC)
Determine whether a tag originally declared in context OldDC can be redeclared with an unqualified na...
static bool isRecordType(QualType T)
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis for OpenMP constructs and clauses.
static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From, QualType T, APValue &Value, Sema::CCEKind CCE, bool RequireInt, NamedDecl *Dest)
CheckConvertedConstantExpression - Check that the expression From is a converted constant expression ...
This file declares semantic analysis for SYCL constructs.
static CharSourceRange getRange(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion)
Defines the SourceManager interface.
C Language Family Type Representation.
const NestedNameSpecifier * Specifier
__DEVICE__ int max(int __a, int __b)
RAII object that pops an ExpressionEvaluationContext when exiting a function body.
ExitFunctionBodyRAII(Sema &S, bool IsLambda)
llvm::APInt getValue() const
virtual void AssignInheritanceModel(CXXRecordDecl *RD)
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
const clang::PrintingPolicy & getPrintingPolicy() const
QualType getParenType(QualType NamedType) const
SourceManager & getSourceManager()
unsigned getIntWidth(QualType T) const
const FunctionType * adjustFunctionType(const FunctionType *Fn, FunctionType::ExtInfo EInfo)
Change the ExtInfo on a function type.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) const
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
ExternCContextDecl * getExternCContextDecl() const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
DeclarationNameTable DeclarationNames
QualType getObjCClassType() const
Represents the Objective-C Class type.
QualType getRecordType(const RecordDecl *Decl) const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
void setObjCIdRedefinitionType(QualType RedefType)
Set the user-written type that redefines id.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl)
Set the type for the C sigjmp_buf type.
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
void setObjCSelRedefinitionType(QualType RedefType)
Set the user-written type that redefines 'SEL'.
void setFILEDecl(TypeDecl *FILEDecl)
Set the type for the C FILE type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const CXXMethodDecl * getCurrentKeyFunction(const CXXRecordDecl *RD)
Get our current best idea for the key function of the given record decl, or nullptr if there isn't on...
bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U) const
Determine whether two function types are the same, ignoring exception specifications in cases where t...
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Builtin::Context & BuiltinInfo
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
void addModuleInitializer(Module *M, Decl *Init)
Add a declaration to the list of declarations that are initialized for a module.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
const LangOptions & getLangOpts() const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
void attachCommentsToJustParsedDecls(ArrayRef< Decl * > Decls, const Preprocessor *PP)
Searches existing comments for doc comments that should be attached to Decls.
void setStaticLocalNumber(const VarDecl *VD, unsigned Number)
const VariableArrayType * getAsVariableArrayType(QualType T) const
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
void setucontext_tDecl(TypeDecl *ucontext_tDecl)
Set the type for the C ucontext_t type.
CanQualType UnsignedLongTy
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
void setNonKeyFunction(const CXXMethodDecl *method)
Observe that the given method cannot be a key function.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, bool Unqualified=false, bool BlockReturnType=false, bool IsConditionalOperator=false)
QualType getObjCIdType() const
Represents the Objective-CC id type.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
void setManglingNumber(const NamedDecl *ND, unsigned Number)
CanQualType UnsignedCharTy
CanQualType UnsignedIntTy
void addDeclaratorForUnnamedTagDecl(TagDecl *TD, DeclaratorDecl *DD)
CanQualType UnsignedLongLongTy
QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, unsigned *IntegerConstantArgs=nullptr) const
Return the type for the specified builtin.
CanQualType UnsignedShortTy
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
void setcudaConfigureCallDecl(FunctionDecl *FD)
const TargetInfo & getTargetInfo() const
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
void setObjCClassRedefinitionType(QualType RedefType)
Set the user-written type that redefines 'SEL'.
bool hasDirectOwnershipQualifier(QualType Ty) const
Return true if the type has been explicitly qualified with ObjC ownership.
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
void ResetObjCLayout(const ObjCContainerDecl *CD)
DeclarationNameInfo getNameForTemplate(TemplateName Name, SourceLocation NameLoc) const
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *) const
QualType getLifetimeQualifiedType(QualType type, Qualifiers::ObjCLifetime lifetime)
Return a type with the given lifetime qualifier.
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
bool typesAreCompatible(QualType T1, QualType T2, bool CompareUnqualified=false)
Compatibility predicates used to check assignment expressions.
void setjmp_bufDecl(TypeDecl *jmp_bufDecl)
Set the type for the C jmp_buf type.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
QualType mergeObjCGCQualifiers(QualType, QualType)
mergeObjCGCQualifiers - This routine merges ObjC's GC attribute of 'LHS' and 'RHS' attributes and ret...
bool isPromotableIntegerType(QualType T) const
More type predicates useful for type checking/promotion.
LangAS getLangASForBuiltinAddressSpace(unsigned AS) const
bool hasSameFunctionTypeIgnoringPtrSizes(QualType T, QualType U)
Determine whether two function types are the same, ignoring pointer sizes in the return type and para...
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
@ GE_Missing_stdio
Missing a type from <stdio.h>
@ GE_Missing_type
Missing a type.
@ GE_Missing_ucontext
Missing a type from <ucontext.h>
@ GE_Missing_setjmp
Missing a type from <setjmp.h>
void addTypedefNameForUnnamedTagDecl(TagDecl *TD, TypedefNameDecl *TND)
TranslationUnitDecl * getTranslationUnitDecl() const
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
The result of parsing/analyzing an expression, statement etc.
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Wrapper for source info for arrays.
SourceLocation getLBracketLoc() const
Expr * getSizeExpr() const
TypeLoc getElementLoc() const
SourceLocation getRBracketLoc() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
Attr * clone(ASTContext &C) const
attr::Kind getKind() const
SourceLocation getLocation() const
@ AS_Declspec
__declspec(...)
SourceRange getRange() const
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
AttributeFactory & getFactory() const
Type source information for an attributed type.
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
An attributed type is a type to which a type attribute has been applied.
QualType getModifiedType() const
bool isCallingConv() const
static Kind getNullabilityAttrKind(NullabilityKind kind)
Retrieve the attribute kind corresponding to the given nullability kind.
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
AutoTypeKeyword getKeyword() const
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isCompoundAssignmentOp(Opcode Opc)
A binding in a decomposition declaration.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
bool doesNotEscape() const
This class is used for builtin types like 'int'.
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
bool performsCallback(unsigned ID, llvm::SmallVectorImpl< int > &Encoding) const
Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details).
bool isAuxBuiltinID(unsigned ID) const
Return true if builtin ID belongs to AuxTarget.
llvm::StringRef getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
bool isReturnsTwice(unsigned ID) const
Return true if we know this builtin can return twice.
bool isConstWithoutErrnoAndExceptions(unsigned ID) const
Return true if this function has no side effects and doesn't read memory, except for possibly errno o...
bool allowTypeMismatch(unsigned ID) const
Determines whether a declaration of this builtin should be recognized even if the type doesn't match ...
bool isTSBuiltin(unsigned ID) const
Return true if this function is a target-specific builtin.
bool isHeaderDependentFunction(unsigned ID) const
Returns true if this builtin requires appropriate header in other compilers.
bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like scanf in its formatting rules and, if so, set the index to the...
bool isInStdNamespace(unsigned ID) const
Determines whether this builtin is a C++ standard library function that lives in (possibly-versioned)...
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like printf in its formatting rules and, if so, set the index to th...
const char * getHeaderName(unsigned ID) const
If this is a library function that comes from a specific header, retrieve that header name.
bool isConstWithoutExceptions(unsigned ID) const
bool isPredefinedRuntimeFunction(unsigned ID) const
Determines whether this builtin is a predefined compiler-rt/libgcc function, such as "__clear_cache",...
bool isPure(unsigned ID) const
Return true if this function has no side effects.
bool isNoThrow(unsigned ID) const
Return true if we know this builtin never throws an exception.
bool isConst(unsigned ID) const
Return true if this function has no side effects and doesn't read memory.
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a base class of a C++ class.
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getEndLoc() const LLVM_READONLY
Represents a call to a C++ constructor.
Expr * getArg(unsigned Arg)
Return the specified argument.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Represents a C++ constructor within a class.
bool isCopyConstructor(unsigned &TypeQuals) const
Whether this constructor is a copy constructor (C++ [class.copy]p2, which can be used to copy the cla...
static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited=InheritedConstructor(), Expr *TrailingRequiresClause=nullptr)
Represents a C++ conversion function within a class.
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
static CXXDeductionGuideDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl *Ctor=nullptr, DeductionCandidate Kind=DeductionCandidate::Normal)
Represents a C++ destructor within a class.
static CXXDestructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, Expr *TrailingRequiresClause=nullptr)
A mapping from each virtual member function to its set of final overriders.
Represents a static or instance method of a struct/union/class.
bool isExplicitObjectMemberFunction() const
[C++2b][dcl.fct]/p7 An explicit object member function is a non-static member function with an explic...
void addOverriddenMethod(const CXXMethodDecl *MD)
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
QualType getFunctionObjectParameterReferenceType() const
Return the type of the object pointed by this.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Qualifiers getMethodQualifiers() const
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
A call to an overloaded operator written using operator syntax.
Represents a C++ struct/union/class.
bool hasNonTrivialCopyAssignment() const
Determine whether this class has a non-trivial copy assignment operator (C++ [class....
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
base_class_iterator bases_end()
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
bool hasNonTrivialDestructor() const
Determine whether this class has a non-trivial destructor (C++ [class.dtor]p3)
unsigned getNumBases() const
Retrieves the number of base classes of this class.
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr, bool DelayTypeCreation=false)
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, bool LookupInDependent=false) const
Look for entities within the base classes of this C++ class, transitively searching all base class su...
base_class_iterator bases_begin()
capture_const_range captures() const
bool hasDefinition() const
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
LambdaCaptureDefault getLambdaCaptureDefault() const
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
void setDescribedClassTemplate(ClassTemplateDecl *Template)
bool hasNonTrivialCopyConstructor() const
Determine whether this class has a non-trivial copy constructor (C++ [class.copy]p6,...
CXXRecordDecl * getDefinition() const
Represents a C++ nested-name-specifier or a global scope specifier.
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
char * location_data() const
Retrieve the data associated with the source-location information.
bool isEmpty() const
No scope specifier.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
bool isCallToStdMove() const
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
CastKind getCastKind() const
static CharSourceRange getCharRange(SourceRange R)
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Declaration of a class template.
ConditionalOperator - The ?: ternary operator.
static unsigned getNumAddressingBits(const ASTContext &Context, QualType ElementType, const llvm::APInt &NumElements)
Determine the number of bits required to address a member of.
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
llvm::APInt getSize() const
Return the constant array size as an APInt.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool isFileContext() const
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
const BlockDecl * getInnermostBlockDecl() const
Return this DeclContext if it is a BlockDecl.
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
void removeDecl(Decl *D)
Removes a declaration from this context.
void addDecl(Decl *D)
Add the declaration D into this context.
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
bool isFunctionOrMethod() const
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
Decl::Kind getDeclKind() const
DeclContext * getNonTransparentContext()
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
A reference to a declared variable, function, enum, etc.
SourceLocation getBeginLoc() const LLVM_READONLY
Captures information about "declaration specifiers".
bool isVirtualSpecified() const
bool isModulePrivateSpecified() const
static const TST TST_typeof_unqualType
bool hasAutoTypeSpec() const
static const TST TST_typename
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
void ClearStorageClassSpecs()
bool isNoreturnSpecified() const
TST getTypeSpecType() const
SourceLocation getStorageClassSpecLoc() const
SCS getStorageClassSpec() const
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceLocation getBeginLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
static const TST TST_interface
static const TST TST_typeofExpr
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
void SetRangeStart(SourceLocation Loc)
SourceLocation getNoreturnSpecLoc() const
bool isExternInLinkageSpec() const
static const TST TST_union
SCS
storage-class-specifier
SourceLocation getExplicitSpecLoc() const
SourceLocation getModulePrivateSpecLoc() const
bool isMissingDeclaratorOk()
Checks if this DeclSpec can stand alone, without a Declarator.
ParsedType getRepAsType() const
void UpdateTypeRep(ParsedType Rep)
TSCS getThreadStorageClassSpec() const
ParsedAttributes & getAttributes()
void ClearTypeQualifiers()
Clear out all of the type qualifiers.
SourceLocation getConstSpecLoc() const
SourceRange getExplicitSpecRange() const
static const TST TST_enum
static const TST TST_decltype
static bool isDeclRep(TST T)
bool isInlineSpecified() const
SourceLocation getRestrictSpecLoc() const
static const TST TST_typeof_unqualExpr
static const TST TST_class
void ClearConstexprSpec()
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
static const TST TST_atomic
SourceLocation getThreadStorageClassSpecLoc() const
Expr * getRepAsExpr() const
static const TST TST_unspecified
SourceLocation getAtomicSpecLoc() const
SourceLocation getVirtualSpecLoc() const
SourceLocation getConstexprSpecLoc() const
SourceLocation getTypeSpecTypeLoc() const
void UpdateExprRep(Expr *Rep)
static const TSCS TSCS_thread_local
static const TST TST_error
ExplicitSpecifier getExplicitSpecifier() const
bool isTypeSpecOwned() const
SourceLocation getInlineSpecLoc() const
SourceLocation getUnalignedSpecLoc() const
Decl * getRepAsDecl() const
SourceLocation getVolatileSpecLoc() const
FriendSpecified isFriendSpecified() const
bool hasExplicitSpecifier() const
bool hasConstexprSpecifier() const
static const TST TST_typeofType
static const TST TST_auto
ConstexprSpecKind getConstexprSpecifier() const
static const TST TST_struct
Decl - This represents one declaration (or definition), e.g.
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
bool isInStdNamespace() const
SourceLocation getEndLoc() const LLVM_READONLY
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
ASTContext & getASTContext() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
void setAttrs(const AttrVec &Attrs)
bool isUnavailable(std::string *Message=nullptr) const
Determine whether this declaration is marked 'unavailable'.
void setLocalExternDecl()
Changes the namespace of this declaration to reflect that it's a function-local extern declaration.
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
Module * getOwningModuleForLinkage(bool IgnoreLinkage=false) const
Get the module that owns this declaration for linkage purposes.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
void setTopLevelDeclInObjCContainer(bool V=true)
bool isInIdentifierNamespace(unsigned NS) const
@ FOK_Undeclared
A friend of a previously-undeclared entity.
@ FOK_None
Not a friend object.
@ FOK_Declared
A friend of a previously-declared entity.
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
bool isReferenced() const
Whether any declaration of this entity was referenced.
bool isFromExplicitGlobalModule() const
Whether this declaration comes from explicit global module.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
@ OBJC_TQ_CSNullability
The nullability qualifier is set when the nullability of the result or parameter was expressed via a ...
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
bool isInvalidDecl() const
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
bool isLocalExternDecl() const
Determine whether this is a block-scope declaration with linkage.
void setAccess(AccessSpecifier AS)
SourceLocation getLocation() const
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
@ IDNS_Ordinary
Ordinary names.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
void setLocalOwningModule(Module *M)
void setImplicit(bool I=true)
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
AccessSpecifier getAccess() const
SourceLocation getBeginLoc() const LLVM_READONLY
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
bool hasOwningModule() const
Is this declaration owned by some module?
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
void setNonMemberOperator()
Specifies that this declaration is a C++ overloaded non-member.
void setLexicalDeclContext(DeclContext *DC)
DeclContext * getDeclContext()
The name of a declaration.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
bool isEmpty() const
Evaluates true when this declaration name is empty.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
Represents a ValueDecl that came out of a declarator.
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
SourceLocation getTypeSpecStartLoc() const
SourceLocation getBeginLoc() const LLVM_READONLY
unsigned getNumTemplateParameterLists() const
void setTypeSourceInfo(TypeSourceInfo *TI)
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
TypeSourceInfo * getTypeSourceInfo() const
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Expr * getTrailingRequiresClause()
Sets a trailing requires clause for this declarator.
FunctionDefinitionKind getFunctionDefinitionKind() const
void setRedeclaration(bool Val)
SourceLocation getIdentifierLoc() const
void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
Expr * getAsmLabel() const
SourceLocation getEndLoc() const LLVM_READONLY
void setInvalidType(bool Val=true)
const ParsedAttributesView & getDeclarationAttributes() const
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
bool isRedeclaration() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isCtorOrDtor()
Returns true if this declares a constructor or a destructor.
bool isFunctionDefinition() const
bool hasInitializer() const
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
void takeAttributes(ParsedAttributes &attrs)
takeAttributes - Takes attributes from the given parsed-attributes set and add them to this declarato...
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
const ParsedAttributes & getAttributes() const
bool isInvalidType() const
bool isExplicitObjectMemberFunction()
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
const DecompositionDeclarator & getDecompositionDeclarator() const
bool isDecompositionDeclarator() const
Return whether this declarator is a decomposition declarator.
TemplateParameterList * getInventedTemplateParameterList() const
The template parameter list generated from the explicit template parameters along with any invented t...
const IdentifierInfo * getIdentifier() const
bool isFirstDeclarationOfMember()
Returns true if this declares a real member and not a friend.
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
bool isStaticMember()
Returns true if this declares a static member.
A decomposition declaration.
static DecompositionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation LSquareLoc, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< BindingDecl * > Bindings)
A parsed C++17 decomposition declarator of the form '[' identifier-list ']'.
SourceRange getSourceRange() const
SourceLocation getLSquareLoc() const
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
void setNameLoc(SourceLocation Loc)
void setElaboratedKeywordLoc(SourceLocation Loc)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Concrete class used by the front-end to report problems and issues.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
void setElaboratedKeywordLoc(SourceLocation Loc)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
An instance of this object exists for each enum constant that is defined.
const Expr * getInitExpr() const
llvm::APSInt getInitVal() const
static EnumConstantDecl * Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
enumerator_range enumerators() const
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
void setIntegerType(QualType T)
Set the underlying integer type.
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
bool isComplete() const
Returns true if this can be considered a complete type.
static EnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed)
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
void setPromotionType(QualType T)
Set the promotion type.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
EvaluatedExprVisitor - This class visits 'Expr *'s.
Store information needed for an explicit specifier.
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
bool isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
Represents difference between two FPOptions values.
void setDisallowOptimizations()
bool isFPConstrained() const
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
bool isZeroLengthBitField(const ASTContext &Ctx) const
Is this a zero-length bit-field? Such bit-fields aren't really bit-fields at all and instead act as a...
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
static FileScopeAsmDecl * Create(ASTContext &C, DeclContext *DC, StringLiteral *Str, SourceLocation AsmLoc, SourceLocation RParenLoc)
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Represents a function declaration or definition.
bool isMultiVersion() const
True if this function is considered a multiversioned function.
ConstexprSpecKind getConstexprKind() const
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
void setPreviousDeclaration(FunctionDecl *PrevDecl)
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
void setIsPureVirtual(bool P=true)
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
void setHasSkippedBody(bool Skipped=true)
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
param_iterator param_end()
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
void setIsMultiVersion(bool V=true)
Sets the multiversion state for this declaration and all of its redeclarations.
QualType getReturnType() const
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
bool hasWrittenPrototype() const
Whether this function has a written prototype.
void setWillHaveBody(bool V=true)
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
param_iterator param_begin()
bool isVariadic() const
Whether this function is variadic.
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
bool isDeleted() const
Whether this function has been deleted.
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
@ TK_MemberSpecialization
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function.
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isDeletedAsWritten() const
void setHasInheritedPrototype(bool P=true)
State that this function inherited its prototype from a previous declaration.
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, Expr *TrailingRequiresClause=nullptr)
bool isExternC() const
Determines whether this function is a function with external, C linkage.
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
bool isImmediateEscalating() const
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
bool hasSkippedBody() const
True if the function was a definition but its body was skipped.
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
bool isReplaceableGlobalAllocationFunction(std::optional< unsigned > *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
bool isThisDeclarationInstantiatedFromAFriendDefinition() const
Determine whether this specific declaration of the function is a friend declaration that was instanti...
void setRangeEnd(SourceLocation E)
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
bool isDefaulted() const
Whether this function is defaulted.
const ParmVarDecl * getNonObjectParameter(unsigned I) const
void setIneligibleOrNotSelected(bool II)
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
ArrayRef< ParmVarDecl * > parameters() const
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any.
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
void setConstexprKind(ConstexprSpecKind CSK)
void setDefaulted(bool D=true)
QualType getDeclaredReturnType() const
Get the declared return type, which may differ from the actual return type if the return type is dedu...
bool isGlobal() const
Determines whether this is a global function.
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
bool hasInheritedPrototype() const
Whether this function inherited its prototype from a previous declaration.
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
DeclarationNameInfo getNameInfo() const
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
FunctionDecl * getDefinition()
Get the definition for this declaration.
void setHasImplicitReturnZero(bool IRZ)
State that falling off this function implicitly returns null/zero.
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
const ParmVarDecl * getParamDecl(unsigned i) const
Represents a prototype with parameter type info, e.g.
ArrayRef< QualType > getParamTypes() const
ArrayRef< QualType > param_types() const
unsigned getNumParams() const
QualType getParamType(unsigned i) const
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
bool isVariadic() const
Whether this function prototype is variadic.
ExtProtoInfo getExtProtoInfo() const
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
FunctionTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this function template, or nullptr if no such declaration exists...
void mergePrevDecl(FunctionTemplateDecl *Prev)
Merge Prev with our RedeclarableTemplateDecl::Common.
FunctionTemplateDecl * getInstantiatedFromMemberTemplate() const
Provides information about a function template specialization, which is a FunctionDecl that has been ...
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
Wrapper for source info for functions.
A class which abstracts out some details necessary for making a call.
ExtInfo withCallingConv(CallingConv cc) const
CallingConv getCC() const
ExtInfo withProducesResult(bool producesResult) const
unsigned getRegParm() const
bool getNoCallerSavedRegs() const
ExtInfo withNoReturn(bool noReturn) const
bool getHasRegParm() const
bool getProducesResult() const
ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const
ExtInfo withRegParm(unsigned RegParm) const
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
static StringRef getNameForCallConv(CallingConv CC)
static ArmStateValue getArmZT0State(unsigned AttrBits)
static ArmStateValue getArmZAState(unsigned AttrBits)
unsigned getRegParmType() const
CallingConv getCallConv() const
QualType getReturnType() const
bool getCmseNSCallAttr() const
@ SME_PStateSMEnabledMask
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
bool isPlaceholder() const
StringRef getName() const
Return the actual identifier string.
iterator - Iterate over the decls of a specified declaration name.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Represents a C array with an unspecified size.
Represents a field injected from an anonymous union/struct into the parent scope.
static IndirectFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id, QualType T, llvm::MutableArrayRef< NamedDecl * > CH)
void setInherited(bool I)
Description of a constructor that was inherited from a base class.
Describes an C or C++ initializer list.
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
Describes the sequence of initializations required to initialize a given object or reference with a s...
step_iterator step_begin() const
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence.
@ SK_ParenthesizedListInit
Initialize an aggreagate with parenthesized list of values.
Describes an entity that is being initialized.
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Represents the declaration of a label.
bool isResolvedMSAsmLabel() const
LabelStmt * getStmt() const
bool isMSAsmLabel() const
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
clang::ObjCRuntime ObjCRuntime
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i....
bool implicitFunctionsAllowed() const
Returns true if implicit function declarations are allowed in the current language mode.
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
std::vector< llvm::Triple > OMPTargetTriples
Triples of the OpenMP targets that the host code codegen should take into account in order to generat...
static SourceLocation findLocationAfterToken(SourceLocation loc, tok::TokenKind TKind, const SourceManager &SM, const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine)
Checks that the given token is the first token that occurs after the given location (this excludes co...
Represents a linkage specification.
static LinkageSpecDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExternLoc, SourceLocation LangLoc, LinkageSpecLanguageIDs Lang, bool HasBraces)
A class for iterating through a result set and possibly filtering out results.
void erase()
Erase the last element returned from this iterator.
Represents the results of name lookup.
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ NotFound
No entity found met the criteria.
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
@ Found
Name lookup found a single declaration that met the criteria.
DeclClass * getAsSingle() const
bool empty() const
Return true if no decls were found.
SourceLocation getNameLoc() const
Gets the location of the identifier.
Filter makeFilter()
Create a filter for this result set.
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
LookupResultKind getResultKind() const
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
DeclarationName getLookupName() const
Gets the name to look up.
@ AmbiguousTagHiding
Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an...
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
virtual unsigned getManglingNumber(const CXXMethodDecl *CallOperator)=0
Retrieve the mangling number of a new lambda expression with the given call operator within this cont...
virtual unsigned getStaticLocalNumber(const VarDecl *VD)=0
Static locals are numbered by source order.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
Describes a module or submodule.
SourceLocation DefinitionLoc
The location of the module definition.
Module * Parent
The parent of this module.
bool isPrivateModule() const
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
bool isModuleImplementation() const
Is this a module implementation.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isModulePartition() const
Is this a module partition.
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
bool isNamedModule() const
Does this Module is a named module of a standard named module?
This represents a decl that may have a name.
bool isLinkageValid() const
True if the computed linkage is valid.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
bool isPlaceholderVar(const LangOptions &LangOpts) const
Visibility getVisibility() const
Determines the visibility of this entity.
bool hasLinkageBeenComputed() const
True if something has required us to compute the linkage of this declaration.
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
bool declarationReplaces(const NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context,...
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
void setModulePrivate()
Specify that this declaration was marked as being private to the module in which it was defined.
bool hasLinkage() const
Determine whether this declaration has linkage.
bool isExternallyVisible() const
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine if the declaration obeys the reserved identifier rules of the given language.
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
SourceRange getLocalSourceRange() const
Retrieve the source range covering just the last part of this nested-name-specifier,...
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool containsErrors() const
Whether this nested name specifier contains an error.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
ObjCCategoryDecl - Represents a category declaration.
ObjCCompatibleAliasDecl - Represents alias of a class.
ObjCContainerDecl - Represents a container for method declarations.
ObjCIvarDecl * getIvarDecl(IdentifierInfo *Id) const
getIvarDecl - This method looks up an ivar in this ContextDecl.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
known_extensions_range known_extensions() const
ObjCIvarDecl - Represents an ObjC instance variable.
static ObjCIvarDecl * Create(ASTContext &C, ObjCContainerDecl *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW=nullptr, bool synthesized=false)
An expression that sends a message to the given Objective-C object or class.
ObjCMethodDecl - Represents an instance or class method declaration.
param_const_iterator param_end() const
param_const_iterator param_begin() const
const ParmVarDecl *const * param_const_iterator
ParmVarDecl *const * param_iterator
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
bool isFragile() const
The inverse of isNonFragile(): does this runtime follow the set of implied behaviors for a "fragile" ...
Wrapper for void* pointer.
static OpaquePtr make(QualType P)
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
bool isAvailableOption(llvm::StringRef Ext, const LangOptions &LO) const
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
@ CSK_Normal
Normal lookup.
SmallVectorImpl< OverloadCandidate >::iterator iterator
void NoteCandidates(PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
When overload resolution fails, prints diagnostic messages containing the candidates in the candidate...
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
SmallVectorImpl< UniqueVirtualMethod >::iterator overriding_iterator
MapType::iterator iterator
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
unsigned getNumExprs() const
Return the number of expressions in this paren list.
void setRParenLoc(SourceLocation Loc)
TypeLoc getInnerLoc() const
void setLParenLoc(SourceLocation Loc)
Sugar for parentheses used when specifying types.
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
ObjCDeclQualifier getObjCDeclQualifier() const
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
QualType getOriginalType() const
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
ParsedAttr - Represents a syntactic attribute.
static const ParsedAttributesView & none()
bool hasAttribute(ParsedAttr::Kind K) const
ParsedAttributes - A collection of parsed attributes.
AttributePool & getPool() const
unsigned getDiagID() const
TypeLoc getPointeeLoc() const
Wrapper for source info for pointers.
void setStarLoc(SourceLocation Loc)
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
PrimitiveDefaultInitializeKind
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
QualType withoutLocalFastQualifiers() const
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
bool isConstant(const ASTContext &Ctx) const
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
bool isObjCGCStrong() const
true when Type is objc's strong.
bool isConstQualified() const
Determine whether this type is const-qualified.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
bool hasNonTrivialObjCLifetime() const
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
@ PCK_Trivial
The type does not fall into any of the following categories.
@ PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
A qualifier set is used to build a set of qualifiers.
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
ObjCLifetime getObjCLifetime() const
Represents a struct/union/class.
bool hasObjectMember() const
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
bool isInjectedClassName() const
Determines whether this declaration represents the injected class name.
virtual void completeDefinition()
Note that the definition of this type is now complete.
field_iterator field_begin() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
void setMemberSpecialization()
Note that this member template is a specialization.
redecl_iterator redecls_end() const
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Base for LValueReferenceType and RValueReferenceType.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
void setNRVOCandidate(const VarDecl *Var)
Set the variable that might be used for the named return value optimization.
Scope - A scope is a transient data structure that is used while parsing the program.
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
DeclContext * getEntity() const
Get the entity corresponding to this scope.
bool isCompoundStmtScope() const
Determine whether this scope is a compound statement scope.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ DeclScope
This is a scope that can contain a declaration.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
DeviceDiagnosticReason
Bitmask to contain the list of reasons a single diagnostic should be emitted, based on its language.
@ Sycl
SYCL specific diagnostic.
@ CudaDevice
CUDA specific diagnostics.
@ Esimd
ESIMD specific diagnostic.
@ All
A flag representing 'all'.
@ OmpDevice
OpenMP specific diagnostic.
HLSLNumThreadsAttr * mergeNumThreadsAttr(Decl *D, const AttributeCommonInfo &AL, int X, int Y, int Z)
HLSLShaderAttr * mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, HLSLShaderAttr::ShaderType ShaderType)
@ KernelNonConstStaticDataVariable
Mode getAlignMode() const
A class which encapsulates the logic for delaying diagnostics during parsing and other processing.
bool shouldDelayDiagnostics()
Determines whether diagnostics should be delayed.
void add(const sema::DelayedDiagnostic &diag)
Adds a delayed diagnostic.
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
Sema - This implements semantic analysis and AST building for C.
StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, IdentifierInfo *Ident, ParsedAttributes &Attrs)
Attr * getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition)
Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a containing class.
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D)
void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl)
void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, LookupResult &OldDecls)
MergeTypedefNameDecl - We just parsed a typedef 'New' which has the same name and scope as a previous...
InternalLinkageAttr * mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL)
void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S)
Register the given locally-scoped extern "C" declaration so that it can be found later for redeclarat...
bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New)
NamedDecl * ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, bool &AddToScope)
OpenCLOptions & getOpenCLOptions()
bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S=nullptr, bool AllowInlineNamespace=false) const
isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true if 'D' is in Scope 'S',...
bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs=true)
SYCLIntelMaxConcurrencyAttr * MergeSYCLIntelMaxConcurrencyAttr(Decl *D, const SYCLIntelMaxConcurrencyAttr &A)
void DiagnoseUnusedParameters(ArrayRef< ParmVarDecl * > Parameters)
Diagnose any unused parameters in the given sequence of ParmVarDecl pointers.
LookupNameKind
Describes the kind of name lookup to perform.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
@ LookupLocalFriendName
Look up a friend of a local class.
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
void DiagnoseFunctionSpecifiers(const DeclSpec &DS)
Diagnose function specifiers on a declaration of an identifier that does not identify a function.
void ActOnPopScope(SourceLocation Loc, Scope *S)
void ActOnDefinedDeclarationSpecifier(Decl *D)
Called once it is known whether a tag declaration is an anonymous union or struct.
Decl * ActOnSkippedFunctionBody(Decl *Decl)
SYCLIntelMaxReplicatesAttr * MergeSYCLIntelMaxReplicatesAttr(Decl *D, const SYCLIntelMaxReplicatesAttr &A)
QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, QualType Type, TypeSourceInfo *TSI, SourceRange Range, bool DirectInit, Expr *Init)
bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, bool MergeTypeWithOld, bool NewDeclIsDefn)
MergeFunctionDecl - We just parsed a function 'New' from declarator D which has the same name and sco...
bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, DeclarationName Name, SourceLocation Loc, TemplateIdAnnotation *TemplateId, bool IsMemberSpecialization)
Diagnose a declaration whose declarator-id has the given nested-name-specifier.
AvailabilityAttr * mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, IdentifierInfo *Platform, bool Implicit, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool IsUnavailable, StringRef Message, bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK, int Priority)
void ActOnTagDefinitionError(Scope *S, Decl *TagDecl)
ActOnTagDefinitionError - Invoked when there was an unrecoverable error parsing the definition of a t...
SYCLIntelNumSimdWorkItemsAttr * MergeSYCLIntelNumSimdWorkItemsAttr(Decl *D, const SYCLIntelNumSimdWorkItemsAttr &A)
void CheckExplicitObjectMemberFunction(Declarator &D, DeclarationName Name, QualType R, bool IsLambda, DeclContext *DC=nullptr)
bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info)
DiagnoseClassNameShadow - Implement C++ [class.mem]p13: If T is the name of a class,...
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, SourceRange BraceRange)
ActOnTagFinishDefinition - Invoked once we have finished parsing the definition of a tag (enumeration...
FunctionEmissionStatus
Status of the function emission on the CUDA/HIP/OpenMP host/device attrs.
NamedDecl * ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, Scope *S)
ImplicitlyDefineFunction - An undeclared identifier was used in a function call, forming a call to an...
Decl * ActOnParamDeclarator(Scope *S, Declarator &D, SourceLocation ExplicitThisLoc={})
ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator() to introduce parameters into fun...
MinSizeAttr * mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI)
void ActOnExitFunctionContext()
ExprResult RebuildExprInCurrentInstantiation(Expr *E)
void deduceOpenCLAddressSpace(ValueDecl *decl)
IntelNamedSubGroupSizeAttr * MergeIntelNamedSubGroupSizeAttr(Decl *D, const IntelNamedSubGroupSizeAttr &A)
PragmaStack< StringLiteral * > CodeSegStack
NamedDecl * HandleDeclarator(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists)
void handleTagNumbering(const TagDecl *Tag, Scope *TagScope)
WebAssemblyImportModuleAttr * mergeImportModuleAttr(Decl *D, const WebAssemblyImportModuleAttr &AL)
void CheckMain(FunctionDecl *FD, const DeclSpec &D)
void AddKnownFunctionAttributes(FunctionDecl *FD)
Adds any function attributes that we know a priori based on the declaration of this function.
void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver)
If VD is set but not otherwise used, diagnose, for a parameter or a variable.
ExprResult VerifyBitField(SourceLocation FieldLoc, const IdentifierInfo *FieldName, QualType FieldTy, bool IsMsStruct, Expr *BitWidth)
VerifyBitField - verifies that a bit field expression is an ICE and has the correct width,...
FieldDecl * HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth, InClassInitStyle InitStyle, AccessSpecifier AS)
HandleField - Analyze a field of a C struct or a C++ data member.
void CheckThreadLocalForLargeAlignment(VarDecl *VD)
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
Look up a name, looking for a single declaration.
void ActOnReenterFunctionContext(Scope *S, Decl *D)
Push the parameters of D, which must be a function, into scope.
sema::LambdaScopeInfo * RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator)
MSInheritanceAttr * mergeMSInheritanceAttr(Decl *D, const AttributeCommonInfo &CI, bool BestCase, MSInheritanceModel Model)
const AttributedType * getCallingConvAttributedType(QualType T) const
Get the outermost AttributedType node that sets a calling convention.
TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S)
isTagName() - This method is called for error recovery purposes only to determine if the specified na...
bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old)
SYCLIntelLoopFuseAttr * MergeSYCLIntelLoopFuseAttr(Decl *D, const SYCLIntelLoopFuseAttr &A)
void CheckConversionDeclarator(Declarator &D, QualType &R, StorageClass &SC)
CheckConversionDeclarator - Called by ActOnDeclarator to check the well-formednes of the conversion f...
Decl * ActOnFileScopeAsmDecl(Expr *expr, SourceLocation AsmLoc, SourceLocation RParenLoc)
ParmVarDecl * BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc, QualType T)
Synthesizes a variable for a parameter arising from a typedef.
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
DeclarationNameInfo GetNameForDeclarator(Declarator &D)
GetNameForDeclarator - Determine the full declaration name for the given Declarator.
void ActOnFinishTopLevelStmtDecl(TopLevelStmtDecl *D, Stmt *Statement)
void * SkippedDefinitionContext
void DiagPlaceholderFieldDeclDefinitions(RecordDecl *Record)
Emit diagnostic warnings for placeholder members.
void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, TypedefNameDecl *NewTD)
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
NamedDecl * LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc)
LazilyCreateBuiltin - The specified Builtin-ID was first used at file scope.
void CheckCoroutineWrapper(FunctionDecl *FD)
bool IsRedefinitionInModule(const NamedDecl *New, const NamedDecl *Old) const
void PopExpressionEvaluationContext()
bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S)
isMicrosoftMissingTypename - In Microsoft mode, within class scope, if a CXXScopeSpec's type is equal...
SYCLAddIRAttributesGlobalVariableAttr * MergeSYCLAddIRAttributesGlobalVariableAttr(Decl *D, const SYCLAddIRAttributesGlobalVariableAttr &A)
SYCLDeviceHasAttr * MergeSYCLDeviceHasAttr(Decl *D, const SYCLDeviceHasAttr &A)
bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn)
We've just determined that Old and New both appear to be definitions of the same variable.
bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee)
Decl * BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, AccessSpecifier AS, RecordDecl *Record, const PrintingPolicy &Policy)
BuildAnonymousStructOrUnion - Handle the declaration of an anonymous structure or union.
bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, bool isDefinition, SourceLocation NewTagLoc, const IdentifierInfo *Name)
Determine whether a tag with a given kind is acceptable as a redeclaration of the given tag declarati...
void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F)
DLLExportAttr * mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI)
void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld)
MergeVarDeclTypes - We parsed a variable 'New' which has the same name and scope as a previous declar...
SYCLAddIRAttributesFunctionAttr * MergeSYCLAddIRAttributesFunctionAttr(Decl *D, const SYCLAddIRAttributesFunctionAttr &A)
ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, NamedDecl *Found, SourceLocation NameLoc, const Token &NextToken)
Act on the result of classifying a name as a specific non-type declaration.
bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS)
ObjCInterfaceDecl * getObjCInterfaceDecl(const IdentifierInfo *&Id, SourceLocation IdLoc, bool TypoCorrection=false)
Look for an Objective-C class in the translation unit.
llvm::function_ref< void(SourceLocation Loc, PartialDiagnostic PD)> DiagReceiverTy
bool CheckEnumUnderlyingType(TypeSourceInfo *TI)
Check that this is a valid underlying type for an enum declaration.
SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, SourceLocation IILoc)
Determine whether the body of an anonymous enumeration should be skipped.
CodeSegAttr * mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, StringRef Name)
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
SYCLIntelPipeIOAttr * MergeSYCLIntelPipeIOAttr(Decl *D, const SYCLIntelPipeIOAttr &A)
void EnterTemplatedContext(Scope *S, DeclContext *DC)
Enter a template parameter scope, after it's been associated with a particular DeclContext.
bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, QualType &T, SourceLocation Loc, unsigned FailedFoldDiagID)
Attempt to fold a variable-sized type to a constant-sized type, returning true if we were successful.
NamedDecl * findLocallyScopedExternCDecl(DeclarationName Name)
Look for a locally scoped extern "C" declaration by the given name.
bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old)
We've determined that New is a redeclaration of Old.
NamedDecl * getShadowedDeclaration(const TypedefNameDecl *D, const LookupResult &R)
Return the declaration shadowed by the given typedef D, or null if it doesn't shadow any declaration ...
DeviceDiagnosticReason getEmissionReason(const FunctionDecl *Decl)
const LangOptions & LangOpts
const LangOptions & getLangOpts() const
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Decl * ActOnStartOfFunctionDef(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParamLists, SkipBodyInfo *SkipBody=nullptr, FnBodyKind BodyKind=FnBodyKind::Other)
bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const
bool CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, LookupResult &Previous, bool IsMemberSpecialization, bool DeclIsDefn)
Perform semantic checking of a new function declaration.
FieldDecl * CheckFieldDecl(DeclarationName Name, QualType T, TypeSourceInfo *TInfo, RecordDecl *Record, SourceLocation Loc, bool Mutable, Expr *BitfieldWidth, InClassInitStyle InitStyle, SourceLocation TSSL, AccessSpecifier AS, NamedDecl *PrevDecl, Declarator *D=nullptr)
Build a new FieldDecl and check its well-formedness.
QualType CheckDestructorDeclarator(Declarator &D, QualType R, StorageClass &SC)
CheckDestructorDeclarator - Called by ActOnDeclarator to check the well-formednes of the destructor d...
EnforceTCBAttr * mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL)
bool canDelayFunctionBody(const Declarator &D)
Determine whether we can delay parsing the body of a function or function template until it is used,...
SYCLAddIRAnnotationsMemberAttr * MergeSYCLAddIRAnnotationsMemberAttr(Decl *D, const SYCLAddIRAnnotationsMemberAttr &A)
EnforceTCBLeafAttr * mergeEnforceTCBLeafAttr(Decl *D, const EnforceTCBLeafAttr &AL)
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, const CXXScopeSpec &SS, QualType T, TagDecl *OwnedTagDecl=nullptr)
Retrieve a version of the type 'T' that is elaborated by Keyword, qualified by the nested-name-specif...
NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, SourceLocation NameLoc, const Token &NextToken, CorrectionCandidateCallback *CCC=nullptr)
Perform name lookup on the given name, classifying it based on the results of name lookup and the fol...
IntelReqdSubGroupSizeAttr * MergeIntelReqdSubGroupSizeAttr(Decl *D, const IntelReqdSubGroupSizeAttr &A)
NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK)
Given a non-tag type declaration, returns an enum useful for indicating what kind of non-tag type thi...
void ExitDeclaratorContext(Scope *S)
void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI)
Diagnose shadowing for variables shadowed in the lambda record LambdaRD when these variables are capt...
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, bool AllowBuiltinCreation=false, bool EnteringContext=false)
Performs name lookup for a name that was parsed in the source code, and may contain a C++ scope speci...
void CheckMSVCRTEntryPoint(FunctionDecl *FD)
UuidAttr * mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, StringRef UuidAsWritten, MSGuidDecl *GuidDecl)
Decl * ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, SourceLocation IdLoc, IdentifierInfo *Id, const ParsedAttributesView &Attrs, SourceLocation EqualLoc, Expr *Val)
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
FunctionDecl * CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, SourceLocation Loc)
Scope * getNonFieldDeclScope(Scope *S)
getNonFieldDeclScope - Retrieves the innermost scope, starting from S, where a non-field would be dec...
void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc)
ActOnPragmaWeakID - Called on well formed #pragma weak ident.
bool CheckNontrivialField(FieldDecl *FD)
void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, SourceLocation FinalLoc, bool IsFinalSpelledSealed, bool IsAbstract, SourceLocation LBraceLoc)
ActOnStartCXXMemberDeclarations - Invoked when we have parsed a C++ record definition's base-specifie...
SYCLAddIRAttributesKernelParameterAttr * MergeSYCLAddIRAttributesKernelParameterAttr(Decl *D, const SYCLAddIRAttributesKernelParameterAttr &A)
bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous)
Perform semantic checking on a newly-created variable declaration.
bool isVisible(const NamedDecl *D)
Determine whether a declaration is visible to name lookup.
FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl, bool Final=false)
bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R, StorageClass &SC)
Check the validity of a declarator that we parsed for a deduction-guide.
bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD)
AddOverriddenMethods - See if a method overrides any in the base classes, and if so,...
void DiagPlaceholderVariableDefinition(SourceLocation Loc)
void CheckForFunctionRedefinition(FunctionDecl *FD, const FunctionDecl *EffectiveDefinition=nullptr, SkipBodyInfo *SkipBody=nullptr)
bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody)
Perform ODR-like check for C/ObjC when merging tag types from modules.
void ActOnFinishInlineFunctionDef(FunctionDecl *D)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
SYCLIntelESimdVectorizeAttr * MergeSYCLIntelESimdVectorizeAttr(Decl *D, const SYCLIntelESimdVectorizeAttr &A)
SYCLIntelSchedulerTargetFmaxMhzAttr * MergeSYCLIntelSchedulerTargetFmaxMhzAttr(Decl *D, const SYCLIntelSchedulerTargetFmaxMhzAttr &A)
ErrorAttr * mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, StringRef NewUserDiagnostic)
FormatAttr * mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Format, int FormatIdx, int FirstArg)
void ActOnDocumentableDecl(Decl *D)
Should be called on all declarations that might have attached documentation comments.
DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name)
Retrieves the declaration name from a parsed unqualified-id.
TypeSourceInfo * RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, SourceLocation Loc, DeclarationName Name)
Rebuilds a type within the context of the current instantiation.
VisibilityAttr * mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, VisibilityAttr::VisibilityType Vis)
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, const IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
bool CheckFunctionConstraints(const FunctionDecl *FD, ConstraintSatisfaction &Satisfaction, SourceLocation UsageLoc=SourceLocation(), bool ForOverloadResolution=false)
Check whether the given function decl's trailing requires clause is satisfied, if any.
SYCLTypeAttr * MergeSYCLTypeAttr(Decl *D, const AttributeCommonInfo &CI, SYCLTypeAttr::SYCLType TypeName)
void CheckShadowingDeclModification(Expr *E, SourceLocation Loc)
Warn if 'E', which is an expression that is about to be modified, refers to a shadowing declaration.
TemplateNameKindForDiagnostics getTemplateNameKindForDiagnostics(TemplateName Name)
void notePreviousDefinition(const NamedDecl *Old, SourceLocation New)
void applyFunctionAttributesBeforeParsingBody(Decl *FD)
ObjCContainerDecl * getObjCDeclContext() const
bool canSkipFunctionBody(Decl *D)
Determine whether we can skip parsing the body of a function definition, assuming we don't care about...
bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, QualType NewT, QualType OldT)
Determines if we can perform a correct type check for D as a redeclaration of PrevDecl.
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
void ActOnObjCContainerFinishDefinition()
SYCLWorkGroupSizeHintAttr * MergeSYCLWorkGroupSizeHintAttr(Decl *D, const SYCLWorkGroupSizeHintAttr &A)
bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, Scope *S, bool MergeTypeWithOld)
Completes the merge of two function declarations that are known to be compatible.
void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, Decl *EnumDecl, ArrayRef< Decl * > Elements, Scope *S, const ParsedAttributesView &Attr)
void EnterDeclaratorContext(Scope *S, DeclContext *DC)
EnterDeclaratorContext - Used when we must lookup names in the context of a declarator's nested name ...
bool areMultiversionVariantFunctionsCompatible(const FunctionDecl *OldFD, const FunctionDecl *NewFD, const PartialDiagnostic &NoProtoDiagID, const PartialDiagnosticAt &NoteCausedDiagIDAt, const PartialDiagnosticAt &NoSupportDiagIDAt, const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, bool ConstexprSupported, bool CLinkageMayDiffer)
Checks if the variant/multiversion functions are compatible.
void ActOnTagStartDefinition(Scope *S, Decl *TagDecl)
ActOnTagStartDefinition - Invoked when we have entered the scope of a tag's definition (e....
bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, const PartialDiagnostic &PD)
Conditionally issue a diagnostic based on the current evaluation context.
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body)
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, bool AllowExplicitConversion=false, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, ConversionSequenceList EarlyConversions=std::nullopt, OverloadCandidateParamOrder PO={}, bool AggregateCandidateDeduction=false)
AddOverloadCandidate - Adds the given function to the set of candidate functions, using the given fun...
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, SourceLocation NameLoc)
Act on the result of classifying a name as an undeclared (ADL-only) non-type declaration.
bool IsAtLeastAsConstrained(NamedDecl *D1, MutableArrayRef< const Expr * > AC1, NamedDecl *D2, MutableArrayRef< const Expr * > AC2, bool &Result)
Check whether the given declaration's associated constraints are at least as constrained than another...
SYCLIntelMaxGlobalWorkDimAttr * MergeSYCLIntelMaxGlobalWorkDimAttr(Decl *D, const SYCLIntelMaxGlobalWorkDimAttr &A)
void ActOnPragmaRedefineExtname(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaRedefineExtname - Called on well formed #pragma redefine_extname oldname newname.
TopLevelStmtDecl * ActOnStartTopLevelStmtDecl(Scope *S)
void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, const LookupResult &R)
Diagnose variable or built-in function shadowing.
SYCLIntelNumBanksAttr * MergeSYCLIntelNumBanksAttr(Decl *D, const SYCLIntelNumBanksAttr &A)
void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor)
Build an exception spec for destructors that don't have one.
OptimizeNoneAttr * mergeOptimizeNoneAttr(Decl *D, const AttributeCommonInfo &CI)
void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx)
void CheckCompleteVariableDeclaration(VarDecl *VD)
SYCLIntelMaxWorkGroupSizeAttr * MergeSYCLIntelMaxWorkGroupSizeAttr(Decl *D, const SYCLIntelMaxWorkGroupSizeAttr &A)
DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, ArrayRef< Decl * > Group)
void MergeVarDecl(VarDecl *New, LookupResult &Previous)
MergeVarDecl - We just parsed a variable 'New' which has the same name and scope as a previous declar...
ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, SourceLocation NameLoc, bool IsTemplateTypeArg)
Attempt to behave like MSVC in situations where lookup of an unqualified type name has failed in a de...
void ActOnLastBitfield(SourceLocation DeclStart, SmallVectorImpl< Decl * > &AllIvarDecls)
ActOnLastBitfield - This routine handles synthesized bitfields rules for class and class extensions.
void mergeDeclAttributes(NamedDecl *New, Decl *Old, AvailabilityMergeKind AMK=AMK_Redeclaration)
mergeDeclAttributes - Copy attributes from the Old decl to the New one.
void MarkUnusedFileScopedDecl(const DeclaratorDecl *D)
If it's a file scoped decl that must warn if not used, keep track of it.
ASTContext & getASTContext() const
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=nullptr, bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, bool IsClassTemplateDeductionContext=true, ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type.
EnumConstantDecl * CheckEnumConstant(EnumDecl *Enum, EnumConstantDecl *LastEnumConst, SourceLocation IdLoc, IdentifierInfo *Id, Expr *val)
bool CheckForConstantInitializer(Expr *Init, unsigned DiagID=diag::err_init_element_not_constant)
type checking declaration initializers (C99 6.7.8)
llvm::SmallPtrSet< const Decl *, 4 > ParsingInitForAutoVars
ParsingInitForAutoVars - a set of declarations with auto types for which we are currently parsing the...
void DiagnoseUnusedNestedTypedefs(const RecordDecl *D)
AlwaysInlineAttr * mergeAlwaysInlineAttr(Decl *D, const AttributeCommonInfo &CI, const IdentifierInfo *Ident)
void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FunctionDecl *FD)
If this function is a C++ replaceable global allocation function (C++2a [basic.stc....
bool inferObjCARCLifetime(ValueDecl *decl)
AvailabilityMergeKind
Describes the kind of merge to perform for availability attributes (including "deprecated",...
@ AMK_Override
Merge availability attributes for an override, which requires an exact match or a weakening of constr...
@ AMK_ProtocolImplementation
Merge availability attributes for an implementation of a protocol requirement.
@ AMK_OptionalProtocolImplementation
Merge availability attributes for an implementation of an optional protocol requirement.
void ActOnDocumentableDecls(ArrayRef< Decl * > Group)
void CheckStaticLocalForDllExport(VarDecl *VD)
Check if VD needs to be dllexport/dllimport due to being in a dllexport/import function.
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
DeclResult ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, const ParsedAttributesView &Attr, AccessSpecifier AS, SourceLocation ModulePrivateLoc, MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl, bool &IsDependent, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, bool IsTypeSpecifier, bool IsTemplateParamOrArg, OffsetOfKind OOK, SkipBodyInfo *SkipBody=nullptr)
This is invoked when we see 'struct foo' or 'struct {'.
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, const ParsedAttributesView &DeclAttrs, RecordDecl *&AnonRecord)
ParsedFreeStandingDeclSpec - This method is invoked when a declspec with no declarator (e....
void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, SourceLocation LocAfterDecls)
void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context)
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
SectionAttr * mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, StringRef Name)
bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl)
Checks if the new declaration declared in dependent context must be put in the same redeclaration cha...
FPOptions & getCurFPFeatures()
void PushDeclContext(Scope *S, DeclContext *DC)
Set the current declaration context until it gets popped.
SourceManager & SourceMgr
SwiftNameAttr * mergeSwiftNameAttr(Decl *D, const SwiftNameAttr &SNA, StringRef Name)
Decl * BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, RecordDecl *Record)
BuildMicrosoftCAnonymousStruct - Handle the declaration of an Microsoft C anonymous structure.
static bool CanBeGetReturnTypeOnAllocFailure(const FunctionDecl *FD)
DiagnosticsEngine & Diags
static bool CanBeGetReturnObject(const FunctionDecl *FD)
QualType AdjustParameterTypeForObjCAutoRefCount(QualType T, SourceLocation NameLoc, TypeSourceInfo *TSInfo)
NamedDecl * ActOnTypedefDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous)
SYCLIntelMaxWorkGroupsPerMultiprocessorAttr * MergeSYCLIntelMaxWorkGroupsPerMultiprocessorAttr(Decl *D, const SYCLIntelMaxWorkGroupsPerMultiprocessorAttr &A)
static bool adjustContextForLocalExternDecl(DeclContext *&DC)
Adjust the DeclContext for a function or variable that might be a function-local external declaration...
void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D)
Common checks for a parameter-declaration that should apply to both function parameters and non-type ...
NamedDecl * ActOnTypedefNameDecl(Scope *S, DeclContext *DC, TypedefNameDecl *D, LookupResult &Previous, bool &Redeclaration)
ActOnTypedefNameDecl - Perform semantic checking for a declaration which declares a typedef-name,...
void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs)
ActOnFinishDelayedAttribute - Invoked when we have finished parsing an attribute for which parsing is...
void DiagnoseUnusedDecl(const NamedDecl *ND)
QualType CheckConstructorDeclarator(Declarator &D, QualType R, StorageClass &SC)
CheckConstructorDeclarator - Called by ActOnDeclarator to check the well-formedness of the constructo...
SYCLUsesAspectsAttr * MergeSYCLUsesAspectsAttr(Decl *D, const SYCLUsesAspectsAttr &A)
void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, bool ConsiderLinkage, bool AllowInlineNamespace)
Filters out lookup results that don't fall within the given scope as determined by isDeclInScope.
void ActOnUninitializedDecl(Decl *dcl)
void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc)
Emit diagnostics if the initializer or any of its explicit or implicitly-generated subexpressions req...
SYCLIntelForcePow2DepthAttr * MergeSYCLIntelForcePow2DepthAttr(Decl *D, const SYCLIntelForcePow2DepthAttr &A)
static Scope * getScopeForDeclContext(Scope *S, DeclContext *DC)
Finds the scope corresponding to the given decl context, if it happens to be an enclosing scope.
TypedefDecl * ParseTypedefDecl(Scope *S, Declarator &D, QualType T, TypeSourceInfo *TInfo)
Subroutines of ActOnDeclarator().
SYCLIntelBankWidthAttr * MergeSYCLIntelBankWidthAttr(Decl *D, const SYCLIntelBankWidthAttr &A)
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
Decl * ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth)
ActOnField - Each field of a C struct/union is passed into this in order to create a FieldDecl object...
TypeVisibilityAttr * mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, TypeVisibilityAttr::VisibilityType Vis)
void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old)
void ActOnCXXForRangeDecl(Decl *D)
Decl * ActOnDeclarator(Scope *S, Declarator &D)
SYCLIntelMinWorkGroupsPerComputeUnitAttr * MergeSYCLIntelMinWorkGroupsPerComputeUnitAttr(Decl *D, const SYCLIntelMinWorkGroupsPerComputeUnitAttr &A)
WebAssemblyImportNameAttr * mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL)
bool CheckRedeclarationInModule(NamedDecl *New, NamedDecl *Old)
ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, bool IsAddressOfOperand)
Act on the result of classifying a name as an undeclared member of a dependent base class.
void ActOnPragmaWeakAlias(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
BTFDeclTagAttr * mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL)
void CheckVariableDeclarationType(VarDecl *NewVD)
Decl * ActOnIvar(Scope *S, SourceLocation DeclStart, Declarator &D, Expr *BitWidth, tok::ObjCKeywordKind visibility)
ActOnIvar - Each ivar field of an objective-c class is passed into this in order to create an IvarDec...
SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD)
Invoked when we enter a tag definition that we're skipping.
bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, Expr *Init)
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
SYCLIntelInitiationIntervalAttr * MergeSYCLIntelInitiationIntervalAttr(Decl *D, const SYCLIntelInitiationIntervalAttr &A)
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
SYCLReqdWorkGroupSizeAttr * MergeSYCLReqdWorkGroupSizeAttr(Decl *D, const SYCLReqdWorkGroupSizeAttr &A)
void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope)
Given the set of return statements within a function body, compute the variables that are subject to ...
void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, NonTrivialCUnionContext UseContext, unsigned NonTrivialKind)
Emit diagnostics if a non-trivial C union type or a struct that contains a non-trivial C union is use...
bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, bool AllowMask) const
IsValueInFlagEnum - Determine if a value is allowed as part of a flag enum.
void DiagnoseUnknownTypeName(IdentifierInfo *&II, SourceLocation IILoc, Scope *S, CXXScopeSpec *SS, ParsedType &SuggestedType, bool IsTemplateName=false)
void DiagnoseSizeOfParametersAndReturnValue(ArrayRef< ParmVarDecl * > Parameters, QualType ReturnTy, NamedDecl *D)
Diagnose whether the size of parameters or return value of a function or obj-c method definition is p...
llvm::SmallVector< std::pair< SourceLocation, const BlockDecl * >, 1 > ImplicitlyRetainedSelfLocs
List of SourceLocations where 'self' is implicitly retained inside a block.
TemplateNameKindForDiagnostics
Describes the detailed kind of a template name. Used in diagnostics.
SYCLIntelNoGlobalWorkOffsetAttr * MergeSYCLIntelNoGlobalWorkOffsetAttr(Decl *D, const SYCLIntelNoGlobalWorkOffsetAttr &A)
void warnOnReservedIdentifier(const NamedDecl *D)
DLLImportAttr * mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI)
bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, QualType EnumUnderlyingTy, bool IsFixed, const EnumDecl *Prev)
Check whether this is a valid redeclaration of a previous enumeration.
void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx)
Invoked when we must temporarily exit the objective-c container scope for parsing/looking-up C constr...
NamedDecl * ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, bool &AddToScope, ArrayRef< BindingDecl * > Bindings=std::nullopt)
ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet)
Act on the result of classifying a name as an overload set.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
StringLiteral - This represents a string literal expression, e.g.
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
StringRef getString() const
Represents the declaration of a struct/union/class/enum.
bool isBeingDefined() const
Return true if this decl is currently being defined.
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
void startDefinition()
Starts the definition of this tag declaration.
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
static TagDecl * castFromDeclContext(const DeclContext *DC)
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
TypedefNameDecl * getTypedefNameForAnonDecl() const
TagKind getTagKind() const
void setBraceRange(SourceRange R)
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
bool canKeyFunctionBeInline() const
Can an out-of-line inline function serve as a key function?
Exposes information about the current target.
virtual bool validateCpuIs(StringRef Name) const
unsigned getShortWidth() const
Return the size of 'signed short' and 'unsigned short' for this target, in bits.
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target,...
virtual bool allowDebugInfoForExternalRef() const
Whether target allows debuginfo types for decl only variables/functions.
unsigned getLongLongWidth() const
getLongLongWidth/Align - Return the size of 'signed long long' and 'unsigned long long' for this targ...
bool isTLSSupported() const
Whether the target supports thread-local storage.
unsigned getMaxTLSAlign() const
Return the maximum alignment (in bits) of a TLS variable.
virtual bool validateCpuSupports(StringRef Name) const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
virtual bool isValidFeatureName(StringRef Feature) const
Determine whether this TargetInfo supports the given feature.
unsigned getCharWidth() const
virtual ParsedTargetAttr parseTargetAttr(StringRef Str) const
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target,...
bool supportsMultiVersioning() const
Identify whether this target supports multiversioning of functions, which requires support for cpu_su...
virtual bool shouldDLLImportComdatSymbols() const
Does this target aim for semantic compatibility with Microsoft C++ code using dllimport/export attrib...
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Location wrapper for a TemplateArgument.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation getRAngleLoc() const
SourceLocation getTemplateLoc() const
Represents a type template specialization; the template must be a class template, a type alias templa...
static bool anyInstantiationDependentTemplateArguments(ArrayRef< TemplateArgumentLoc > Args)
Token - This structure provides full information about a lexed token.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool isNot(tok::TokenKind K) const
A declaration that models statements at global scope.
static TopLevelStmtDecl * Create(ASTContext &C, Stmt *Statement)
Represents a declaration of a type.
void setTypeForDecl(const Type *TD)
const Type * getTypeForDecl() const
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Base wrapper for a particular "section" of type source info.
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
TypeLoc IgnoreParens() const
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
void initializeFullCopy(TypeLoc Other)
Initializes this by copying its information from another TypeLoc of the same type.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
SourceLocation getTemplateKeywordLoc() const
Get the SourceLocation of the template keyword (if any).
SourceLocation getEndLoc() const
Get the end source location.
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
SourceLocation getBeginLoc() const
Get the begin source location.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
static StringRef getTagTypeKindName(TagTypeKind Kind)
static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into a tag type kind.
The base class of the type hierarchy.
bool isSizelessType() const
As an extension, we classify types as one of "sized" or "sizeless"; every type is one or the other.
bool isStructureType() const
bool isDecltypeType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isDependentSizedArrayType() const
bool isBlockPointerType() const
bool isBooleanType() const
bool isFunctionReferenceType() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
bool isIncompleteArrayType() const
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
bool isDependentAddressSpaceType() const
bool isConstantArrayType() const
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
bool isVoidPointerType() const
bool isFunctionPointerType() const
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
bool isPointerType() const
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
bool isScalarType() const
bool isVariableArrayType() const
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isSampledImageType() const
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isBitIntType() const
bool isOpenCLSpecificType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type.
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
const RecordType * getAsStructureType() const
bool isWebAssemblyTableType() const
Returns true if this is a WebAssembly table type: either an array of reference types,...
bool containsErrors() const
Whether this type is an error type.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isAtomicType() const
bool isFunctionProtoType() const
bool isObjCIdType() const
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
bool isObjCObjectType() const
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const
Return the implicit lifetime for this type, which must not be dependent.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
const T * getAsAdjusted() const
Member-template getAsAdjusted<specific type>.
bool isFunctionType() const
bool isObjCObjectPointerType() const
bool isMemberFunctionPointerType() const
bool isRVVSizelessBuiltinType() const
Returns true for RVV scalable vector types.
bool isFloatingType() const
bool isAnyPointerType() const
TypeClass getTypeClass() const
bool hasAutoForTrailingReturnType() const
Determine whether this type was written with a leading 'auto' corresponding to a trailing return type...
const T * getAs() const
Member-template getAs<specific type>'.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
bool isNullPtrType() const
bool isRecordType() const
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
bool isFunctionNoProtoType() const
bool isReserveIDT() const
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
bool isSizelessVectorType() const
Returns true for all scalable vector types.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
static TypedefDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Base class for declarations which introduce a typedef-name.
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
TypeSourceInfo * getTypeSourceInfo() const
QualType getUnderlyingType() const
void setTypeSourceInfo(TypeSourceInfo *newType)
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes,...
TypedefNameDecl * getDecl() const
Simple class containing the result of Sema::CorrectTypo.
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
IdentifierInfo * getCorrectionAsIdentifierInfo() const
SmallVectorImpl< NamedDecl * >::const_iterator const_decl_iterator
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
unsigned getEditDistance(bool Normalized=true) const
Gets the "edit distance" of the typo correction from the typo.
SmallVectorImpl< NamedDecl * >::iterator decl_iterator
void setCorrectionDecl(NamedDecl *CDecl)
Clears the list of NamedDecls before adding the new one.
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
static bool isIncrementDecrementOp(Opcode Op)
Represents a C++ unqualified-id that has been parsed.
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
TemplateIdAnnotation * TemplateId
When Kind == IK_TemplateId or IK_ConstructorTemplateId, the template-id annotation that contains the ...
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent)
The iterator over UnresolvedSets.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
void setType(QualType newType)
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Represents a variable declaration or definition.
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
void setCXXForRangeDecl(bool FRD)
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
TLSKind getTLSKind() const
void setInitStyle(InitializationStyle Style)
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a static data member.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
bool isCXXCondDecl() const
@ ListInit
Direct list-initialization (C++11)
@ ParenListInit
Parenthesized list-initialization (C++20)
@ CallInit
Call-style initialization (C++98)
void setStorageClass(StorageClass SC)
void setPreviousDeclInSameBlockScope(bool Same)
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
void setInlineSpecified()
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
const Expr * getInit() const
void setTSCSpec(ThreadStorageClassSpecifier TSC)
bool isInline() const
Whether this variable is (C++1z) inline.
ThreadStorageClassSpecifier getTSCSpec() const
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
VarDecl * getInitializingDeclaration()
Get the initializing declaration of this variable, if any.
void setConstexpr(bool IC)
@ TLS_Static
TLS with a known-constant initializer.
@ TLS_Dynamic
TLS with a dynamic initializer.
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
@ TentativeDefinition
This declaration is a tentative definition.
@ DeclarationOnly
This declaration is only a declaration.
@ Definition
This declaration is definitely a definition.
void setDescribedVarTemplate(VarTemplateDecl *Template)
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
void setImplicitlyInline()
bool isThisDeclarationADemotedDefinition() const
If this definition should pretend to be a declaration.
bool isPreviousDeclInSameBlockScope() const
Whether this local extern variable declaration's previous declaration was declared in the same block ...
bool hasDependentAlignment() const
Determines if this variable's alignment is dependent.
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
void demoteThisDefinitionToDeclaration()
This is a definition which should be demoted to a declaration.
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
static VarTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl)
Create a variable template node.
VarTemplateDecl * getInstantiatedFromMemberTemplate() const
Represents a C array with a specified size that is not an integer-constant-expression.
Expr * getSizeExpr() const
Captures information about a #pragma weak directive.
void disableCheckFallThrough()
bool isVariableCapture() const
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
ValueDecl * getVariable() const
void addVLATypeCapture(SourceLocation Loc, const VariableArrayType *VLAType, QualType CaptureType)
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
SmallVector< Capture, 4 > Captures
Captures - The captures.
ImplicitCaptureStyle ImpCaptureStyle
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType, bool ByCopy)
void addCapture(ValueDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
static DelayedDiagnostic makeForbiddenType(SourceLocation loc, unsigned diagnostic, QualType type, unsigned argument)
Retains information about a function, method, or block that is currently being parsed.
bool UsesFPIntrin
Whether this function uses constrained floating point intrinsics.
bool NeedsScopeChecking() const
bool ObjCShouldCallSuper
A flag that is set when parsing a method that must call super's implementation, such as -dealloc,...
bool ObjCWarnForNoInitDelegation
This starts true for a secondary initializer method and will be set to false if there is an invocatio...
bool HasPotentialAvailabilityViolations
Whether we make reference to a declaration that could be unavailable.
bool ObjCWarnForNoDesignatedInitChain
This starts true for a method marked as designated initializer and will be set to false if there is a...
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
ParmVarDecl * ExplicitObjectParameter
llvm::SmallVector< ShadowedOuterDecl, 4 > ShadowingDecls
CXXRecordDecl * Lambda
The class that describes the lambda.
bool AfterParameterList
Indicate that we parsed the parameter list at which point the mutability of the lambda is known.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
bool Mutable
Whether this is a mutable lambda.
Provides information about an attempted template argument deduction, whose success or failure was des...
Defines the clang::TargetInfo interface.
bool evaluateRequiredTargetFeatures(llvm::StringRef RequiredFatures, const llvm::StringMap< bool > &TargetFetureMap)
Returns true if the required target features of a builtin function are enabled.
constexpr XRayInstrMask None
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< RecordType > recordType
Matches record types (e.g.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
static constexpr Variable var(Literal L)
Returns the variable of L.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
bool Init(InterpState &S, CodePtr OpPC)
bool randomizeStructureLayout(const ASTContext &Context, RecordDecl *RD, llvm::SmallVectorImpl< Decl * > &FinalOrdering)
uint32_t TypeID
An ID number that refers to a type in an AST file.
std::string toString(const til::SExpr *E)
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
The JSON file list parser is used to communicate input to InstallAPI.
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
TypeSpecifierType
Specifies the kind of type.
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
@ OR_Deleted
Succeeded, but refers to a deleted function.
@ OR_Success
Overload resolution succeeded.
@ OR_Ambiguous
Ambiguous candidates found.
@ OR_No_Viable_Function
No viable function found.
@ GVA_AvailableExternally
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
ConstexprSpecKind
Define the kind of constexpr specifier.
InClassInitStyle
In-class initialization styles for non-static data members.
@ ICIS_NoInit
No in-class initializer.
OverloadCandidateDisplayKind
@ OCD_AmbiguousCandidates
Requests that only tied-for-best candidates be shown.
@ OCD_AllCandidates
Requests that all candidates be shown.
@ LCK_ByRef
Capturing by reference.
@ LCK_StarThis
Capturing the *this object by copy.
@ IK_DeductionGuideName
A deduction-guide name (a template-name)
@ IK_ImplicitSelfParam
An implicit 'self' parameter.
@ IK_TemplateId
A template-id, e.g., f<int>.
@ IK_ConstructorTemplateId
A constructor named via a template-id.
@ IK_ConstructorName
A constructor name.
@ IK_LiteralOperatorId
A user-defined literal name, e.g., operator "" _i.
@ IK_Identifier
An identifier.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
@ IK_ConversionFunctionId
A conversion function name, e.g., operator int.
TemplateDecl * getAsTypeTemplateDecl(Decl *D)
bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D)
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
StorageClass
Storage classes.
ThreadStorageClassSpecifier
Thread storage-class-specifier.
@ TSCS_thread_local
C++11 thread_local.
@ TSCS__Thread_local
C11 _Thread_local.
@ TSCS___thread
GNU __thread.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
InheritableAttr * getDLLAttr(Decl *D)
Return a DLL attribute from the declaration.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Parameter
The parameter type of a method or function.
bool supportsVariadicCall(CallingConv CC)
Checks whether the given calling convention supports variadic calls.
TagTypeKind
The kind of a tag type.
@ Interface
The "__interface" keyword.
@ Struct
The "struct" keyword.
@ Class
The "class" keyword.
@ Union
The "union" keyword.
@ Enum
The "enum" keyword.
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: ' ', '\t',...
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
bool isDiscardableGVALinkage(GVALinkage L)
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ CanNeverPassInRegs
The argument of this type cannot be passed directly in registers.
@ TU_Complete
The translation unit is a complete translation unit.
int hasAttribute(AttributeCommonInfo::Syntax Syntax, const IdentifierInfo *Scope, const IdentifierInfo *Attr, const TargetInfo &Target, const LangOptions &LangOpts)
Return the version number associated with the attribute if we recognize and implement the attribute s...
CXXSpecialMemberKind
Kinds of C++ special members.
@ TNK_Type_template
The name refers to a template whose specialization produces a type.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
const FunctionProtoType * T
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
TemplateDeductionResult
Describes the result of template argument deduction.
@ Success
Template argument deduction was successful.
@ AlreadyDiagnosed
Some error which was already diagnosed.
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
@ None
No keyword precedes the qualified type name.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
@ EST_None
no exception specification
@ EST_BasicNoexcept
noexcept
Visibility
Describes the different kinds of visibility that a declaration may have.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
MutableArrayRef< Expr * > MultiExprArg
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
unsigned hasPrototype
hasPrototype - This is true if the function had at least one typed parameter.
ArrayRef< NamedDecl * > getDeclsInPrototype() const
Get the non-parameter decls defined within this function prototype.
const IdentifierInfo * Ident
One instance of this struct is used for each type in a declarator that is parsed.
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
MemberPointerTypeInfo Mem
enum clang::DeclaratorChunk::@219 Kind
static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, bool lvalue)
Return a DeclaratorChunk for a reference.
const ParsedAttributesView & getAttrs() const
If there are attributes applied to this declaratorchunk, return them.
RetTy visit(QualType FT, Ts &&... Args)
EvalResult is a struct with detailed info about an evaluated expression.
Extra information about a function prototype.
unsigned AArch64SMEAttributes
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Contains information gathered from parsing the contents of TargetAttr.
std::vector< std::string > Features
Describes how types, statements, expressions, and declarations should be printed.
Information about a template-id annotation token.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
unsigned NumArgs
NumArgs - The number of template arguments.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.